Skip to content

Commit 203c049

Browse files
author
Johan Vos
committed
8357714: AudioClip.play crash on macOS when loading resource from jar
Reviewed-by: angorya, almatvee
1 parent e0f8e72 commit 203c049

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

modules/javafx.media/src/main/native/jfxmedia/platform/osx/OSXMediaPlayer.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -327,15 +327,17 @@ - (void) stop
327327
if ([scheme caseInsensitiveCompare:@"jar"] == NSOrderedSame ||
328328
[scheme caseInsensitiveCompare:@"jrt"] == NSOrderedSame) {
329329
CJavaInputStreamCallbacks *callbacks = new (nothrow) CJavaInputStreamCallbacks();
330-
if (callbacks == NULL) {
330+
jobject jConnectionHolder = CLocator::CreateConnectionHolder(env, jLocator);
331+
if (callbacks == NULL || jConnectionHolder == NULL) {
332+
if (callbacks) delete callbacks;
331333
[mediaURL release];
332334
LOGGER_WARNMSG("OSXMediaPlayer: Unable to create CJavaInputStreamCallbacks\n");
333335
ThrowJavaException(env, "com/sun/media/jfxmedia/MediaException",
334336
"OSXMediaPlayer: Unable to create CJavaInputStreamCallbacks");
335337
return;
336338
}
337339

338-
if (!callbacks->Init(env, jLocator)) {
340+
if (!callbacks->Init(env, jConnectionHolder)) {
339341
[mediaURL release];
340342
delete callbacks;
341343
LOGGER_WARNMSG("OSXMediaPlayer: callbacks->Init() failed\n");

modules/javafx.media/src/main/native/jfxmedia/platform/osx/avf/AVFMediaPlayer.mm

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -780,10 +780,6 @@ - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
780780
}
781781

782782
if (dataRequest != nil) {
783-
long position = locatorStream->GetCallbacks()->Seek(dataRequest.requestedOffset);
784-
if (position != dataRequest.requestedOffset) {
785-
return NO;
786-
}
787783

788784
// If requestsAllDataToEndOfResource is YES, than requestedLength is
789785
// invalid and we need to provide all data to the end of file.
@@ -803,8 +799,23 @@ - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
803799
}
804800

805801
NSMutableData* readData = nil;
802+
bool isRandomAccess = locatorStream->GetCallbacks()->IsRandomAccess();
803+
int64_t position = -1;
804+
if (isRandomAccess) {
805+
position = dataRequest.requestedOffset;
806+
} else {
807+
position = locatorStream->GetCallbacks()->Seek(dataRequest.requestedOffset);
808+
if (position != dataRequest.requestedOffset) {
809+
return NO;
810+
}
811+
}
806812
while (requestedLength > 0) {
807-
unsigned int blockSize = locatorStream->GetCallbacks()->ReadNextBlock();
813+
unsigned int blockSize = -1;
814+
if (isRandomAccess) {
815+
blockSize = locatorStream->GetCallbacks()->ReadBlock(position, requestedLength);
816+
} else {
817+
blockSize = locatorStream->GetCallbacks()->ReadNextBlock();
818+
}
808819
if (blockSize <= 0) {
809820
break;
810821
}
@@ -818,6 +829,7 @@ - (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader
818829
[loadingRequest.dataRequest respondWithData:readData];
819830

820831
requestedLength -= readSize;
832+
position += readSize;
821833
}
822834

823835
[loadingRequest finishLoading];

0 commit comments

Comments
 (0)