Make Util.inferContentType marginally smarter

Issue: #2513

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=150310349
This commit is contained in:
olly 2017-03-16 05:53:58 -07:00 committed by Oliver Woodman
parent 2fe478ad6a
commit b98de975f1
2 changed files with 19 additions and 7 deletions

View file

@ -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),

View file

@ -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. * Makes a best guess to infer the type from a file name.
* *
@ -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;
} }