1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -422,7 +422,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
422
422
InputStream stream = getInputStream (uri );
423
423
stream .close ();
424
424
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
426
426
}
427
427
428
428
if (isConnected ) {
@@ -438,7 +438,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
438
438
} else {
439
439
if (contentType == null || !MediaManager .canPlayContentType (contentType )) {
440
440
// Try content based on file name.
441
- contentType = MediaUtils .filenameToContentType (uriString );
441
+ contentType = MediaUtils .filenameToContentType (uri . getPath () );
442
442
443
443
if (Locator .DEFAULT_CONTENT_TYPE .equals (contentType )) {
444
444
// Try content based on file signature.
@@ -469,7 +469,7 @@ public void init() throws URISyntaxException, IOException, FileNotFoundException
469
469
}
470
470
else {
471
471
// in case of iPod files we can be sure all files are supported
472
- contentType = MediaUtils .filenameToContentType (uriString );
472
+ contentType = MediaUtils .filenameToContentType (uri . getPath () );
473
473
}
474
474
475
475
if (Logger .canLog (Logger .WARNING )) {
@@ -597,27 +597,38 @@ public void setConnectionProperty(String property, Object value) {
597
597
}
598
598
599
599
public ConnectionHolder createConnectionHolder () throws IOException {
600
- // first check if it's cached
600
+ // check if it's cached
601
601
if (null != cacheEntry ) {
602
602
if (Logger .canLog (Logger .DEBUG )) {
603
603
Logger .logMsg (Logger .DEBUG , "Locator.createConnectionHolder: media cached, creating memory connection holder" );
604
604
}
605
605
return ConnectionHolder .createMemoryConnectionHolder (cacheEntry .getBuffer ());
606
606
}
607
607
608
- // then fall back on other methods
609
- ConnectionHolder holder ;
608
+ // check if it is local file
610
609
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 );
618
620
}
619
621
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
+ }
621
632
}
622
633
623
634
private String getContentTypeFromFileSignature (URI uri ) throws MalformedURLException , IOException {
0 commit comments