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
}
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),
......
......@@ -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.
*
* @param fileName Name of the file. It can include the path of the file.
......@@ -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;
}
......
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