Commit b98de975 by olly Committed by Oliver Woodman

Make Util.inferContentType marginally smarter

Issue: #2513

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=150310349
parent 2fe478ad
...@@ -316,8 +316,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay ...@@ -316,8 +316,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
} }
private MediaSource buildMediaSource(Uri uri, String overrideExtension) { private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
: uri.getLastPathSegment()); : Util.inferContentType("." + overrideExtension);
switch (type) { switch (type) {
case C.TYPE_SS: case C.TYPE_SS:
return new SsMediaSource(uri, buildDataSourceFactory(false), return new SsMediaSource(uri, buildDataSourceFactory(false),
......
...@@ -791,6 +791,18 @@ public final class Util { ...@@ -791,6 +791,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. * Makes a best guess to infer the type from a file name.
* *
* @param fileName Name of the file. It can include the path of the file. * @param fileName Name of the file. It can include the path of the file.
...@@ -798,14 +810,14 @@ public final class Util { ...@@ -798,14 +810,14 @@ public final class Util {
*/ */
@C.ContentType @C.ContentType
public static int inferContentType(String fileName) { public static int inferContentType(String fileName) {
if (fileName == null) { fileName = fileName.toLowerCase();
return C.TYPE_OTHER; if (fileName.endsWith(".mpd")) {
} else if (fileName.endsWith(".mpd")) {
return C.TYPE_DASH; return C.TYPE_DASH;
} else if (fileName.endsWith(".ism") || fileName.endsWith(".isml")) {
return C.TYPE_SS;
} else if (fileName.endsWith(".m3u8")) { } else if (fileName.endsWith(".m3u8")) {
return C.TYPE_HLS; 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 { } else {
return C.TYPE_OTHER; return C.TYPE_OTHER;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment