Skip to content

Commit d1110f4

Browse files
author
Alexander Matveev
committedApr 12, 2022
8282054: Mediaplayer not working with HTTP Live Stream link with query parameter appended with file extension m3u8
Reviewed-by: kcr, arapte
1 parent 6d12638 commit d1110f4

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed
 

‎modules/javafx.media/src/main/java/com/sun/media/jfxmedia/locator/Locator.java

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, 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
@@ -422,7 +422,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
422422
InputStream stream = getInputStream(uri);
423423
stream.close();
424424
isConnected = true;
425-
contentType = MediaUtils.filenameToContentType(uriString); // We need to provide at least something
425+
contentType = MediaUtils.filenameToContentType(uri.getPath()); // We need to provide at least something
426426
}
427427

428428
if (isConnected) {
@@ -438,7 +438,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
438438
} else {
439439
if (contentType == null || !MediaManager.canPlayContentType(contentType)) {
440440
// Try content based on file name.
441-
contentType = MediaUtils.filenameToContentType(uriString);
441+
contentType = MediaUtils.filenameToContentType(uri.getPath());
442442

443443
if (Locator.DEFAULT_CONTENT_TYPE.equals(contentType)) {
444444
// Try content based on file signature.
@@ -469,7 +469,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
469469
}
470470
else {
471471
// in case of iPod files we can be sure all files are supported
472-
contentType = MediaUtils.filenameToContentType(uriString);
472+
contentType = MediaUtils.filenameToContentType(uri.getPath());
473473
}
474474

475475
if (Logger.canLog(Logger.WARNING)) {
@@ -597,27 +597,38 @@ public void setConnectionProperty(String property, Object value) {
597597
}
598598

599599
public ConnectionHolder createConnectionHolder() throws IOException {
600-
// first check if it's cached
600+
// check if it's cached
601601
if (null != cacheEntry) {
602602
if (Logger.canLog(Logger.DEBUG)) {
603603
Logger.logMsg(Logger.DEBUG, "Locator.createConnectionHolder: media cached, creating memory connection holder");
604604
}
605605
return ConnectionHolder.createMemoryConnectionHolder(cacheEntry.getBuffer());
606606
}
607607

608-
// then fall back on other methods
609-
ConnectionHolder holder;
608+
// check if it is local file
610609
if ("file".equals(scheme)) {
611-
holder = ConnectionHolder.createFileConnectionHolder(uri);
612-
} else if (uri.toString().endsWith(".m3u8") || uri.toString().endsWith(".m3u")) {
613-
holder = ConnectionHolder.createHLSConnectionHolder(uri);
614-
} else {
615-
synchronized (propertyLock) {
616-
holder = ConnectionHolder.createURIConnectionHolder(uri, connectionProperties);
617-
}
610+
return ConnectionHolder.createFileConnectionHolder(uri);
611+
}
612+
613+
// check if it is HTTP Live Streaming
614+
// - uri path ends with .m3u8 or .m3u
615+
// - contentType is "application/vnd.apple.mpegurl" or "audio/mpegurl"
616+
String uriPath = uri.getPath();
617+
if (uriPath != null && (uriPath.endsWith(".m3u8") ||
618+
uriPath.endsWith(".m3u"))) {
619+
return ConnectionHolder.createHLSConnectionHolder(uri);
618620
}
619621

620-
return holder;
622+
String type = getContentType(); // Should be ready by now
623+
if (type != null && (type.equals(MediaUtils.CONTENT_TYPE_M3U8) ||
624+
type.equals(MediaUtils.CONTENT_TYPE_M3U))) {
625+
return ConnectionHolder.createHLSConnectionHolder(uri);
626+
}
627+
628+
// media file over http/https
629+
synchronized (propertyLock) {
630+
return ConnectionHolder.createURIConnectionHolder(uri, connectionProperties);
631+
}
621632
}
622633

623634
private String getContentTypeFromFileSignature(URI uri) throws MalformedURLException, IOException {

‎modules/javafx.media/src/main/java/com/sun/media/jfxmediaimpl/MediaUtils.java

+36-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2022, 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
@@ -158,49 +158,62 @@ else if ((buf[8] & 0xff) == 0x69 && (buf[9] & 0xff) == 0x73 && (buf[10] & 0xff)
158158
contentType = CONTENT_TYPE_MP4;
159159
else if ((buf[8] & 0xff) == 0x4D && (buf[9] & 0xff) == 0x50 && (buf[10] & 0xff) == 0x34 && (buf[11] & 0xff) == 0x20) // 'MP4 '
160160
contentType = CONTENT_TYPE_MP4;
161+
} else if ((buf[0] & 0xff) == 0x23
162+
&& (buf[1] & 0xff) == 0x45
163+
&& (buf[2] & 0xff) == 0x58
164+
&& (buf[3] & 0xff) == 0x54
165+
&& (buf[4] & 0xff) == 0x4d
166+
&& (buf[5] & 0xff) == 0x33
167+
&& (buf[6] & 0xff) == 0x55) { // "#EXTM3U"
168+
contentType = CONTENT_TYPE_M3U8;
161169
} else {
162170
throw new MediaException("Unrecognized file signature!");
163171
}
164172

165173
return contentType;
166174
}
167-
168175
/**
169176
* Returns the content type given the file name.
170177
*
171178
* @param filename
172179
* @return content type
173180
*/
174181
public static String filenameToContentType(String filename) {
175-
String contentType = Locator.DEFAULT_CONTENT_TYPE;
182+
if (filename == null) {
183+
return Locator.DEFAULT_CONTENT_TYPE;
184+
}
176185

177186
int dotIndex = filename.lastIndexOf(".");
178-
179187
if (dotIndex != -1) {
180188
String extension = filename.toLowerCase().substring(dotIndex + 1);
181189

182-
if (extension.equals(FILE_TYPE_AIF) || extension.equals(FILE_TYPE_AIFF)) {
183-
contentType = CONTENT_TYPE_AIFF;
184-
} else if (extension.equals(FILE_TYPE_FLV) || extension.equals(FILE_TYPE_FXM)) {
185-
contentType = CONTENT_TYPE_JFX;
186-
} else if (extension.equals(FILE_TYPE_MPA)) {
187-
contentType = CONTENT_TYPE_MPA;
188-
} else if (extension.equals(FILE_TYPE_WAV)) {
189-
contentType = CONTENT_TYPE_WAV;
190-
} else if (extension.equals(FILE_TYPE_MP4)) {
191-
contentType = CONTENT_TYPE_MP4;
192-
} else if (extension.equals(FILE_TYPE_M4A)) {
193-
contentType = CONTENT_TYPE_M4A;
194-
} else if (extension.equals(FILE_TYPE_M4V)) {
195-
contentType = CONTENT_TYPE_M4V;
196-
} else if (extension.equals(FILE_TYPE_M3U8)) {
197-
contentType = CONTENT_TYPE_M3U8;
198-
} else if (extension.equals(FILE_TYPE_M3U)) {
199-
contentType = CONTENT_TYPE_M3U;
190+
switch (extension) {
191+
case FILE_TYPE_AIF:
192+
case FILE_TYPE_AIFF:
193+
return CONTENT_TYPE_AIFF;
194+
case FILE_TYPE_FLV:
195+
case FILE_TYPE_FXM:
196+
return CONTENT_TYPE_JFX;
197+
case FILE_TYPE_MPA:
198+
return CONTENT_TYPE_MPA;
199+
case FILE_TYPE_WAV:
200+
return CONTENT_TYPE_WAV;
201+
case FILE_TYPE_MP4:
202+
return CONTENT_TYPE_MP4;
203+
case FILE_TYPE_M4A:
204+
return CONTENT_TYPE_M4A;
205+
case FILE_TYPE_M4V:
206+
return CONTENT_TYPE_M4V;
207+
case FILE_TYPE_M3U8:
208+
return CONTENT_TYPE_M3U8;
209+
case FILE_TYPE_M3U:
210+
return CONTENT_TYPE_M3U;
211+
default:
212+
break;
200213
}
201214
}
202215

203-
return contentType;
216+
return Locator.DEFAULT_CONTENT_TYPE;
204217
}
205218

206219
/**

0 commit comments

Comments
 (0)
Please sign in to comment.