diff --git a/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java index ffe6bb1fee..adb04eaa24 100644 --- a/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java +++ b/demo/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java @@ -316,8 +316,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay } private MediaSource buildMediaSource(Uri uri, String overrideExtension) { - int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension - : uri.getLastPathSegment()); + int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri) + : Util.inferContentType("." + overrideExtension); switch (type) { case C.TYPE_SS: return new SsMediaSource(uri, buildDataSourceFactory(false), diff --git a/library/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/src/main/java/com/google/android/exoplayer2/util/Util.java index 60846170b9..d9282700d7 100644 --- a/library/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -790,6 +790,18 @@ public final class Util { } } + /** + * Makes a best guess to infer the type from a {@link Uri}. + * + * @param uri The {@link Uri}. + * @return The content type. + */ + @C.ContentType + public static int inferContentType(Uri uri) { + String path = uri.getPath(); + return path == null ? C.TYPE_OTHER : inferContentType(path); + } + /** * Makes a best guess to infer the type from a file name. * @@ -798,14 +810,14 @@ public final class Util { */ @C.ContentType public static int inferContentType(String fileName) { - if (fileName == null) { - return C.TYPE_OTHER; - } else if (fileName.endsWith(".mpd")) { + fileName = fileName.toLowerCase(); + if (fileName.endsWith(".mpd")) { return C.TYPE_DASH; - } else if (fileName.endsWith(".ism") || fileName.endsWith(".isml")) { - return C.TYPE_SS; } else if (fileName.endsWith(".m3u8")) { return C.TYPE_HLS; + } else if (fileName.endsWith(".ism") || fileName.endsWith(".isml") + || fileName.endsWith(".ism/manifest") || fileName.endsWith(".isml/manifest")) { + return C.TYPE_SS; } else { return C.TYPE_OTHER; }