mirror of
https://github.com/samsonjs/media.git
synced 2026-04-13 12:35:48 +00:00
Make Util.inferContentType marginally smarter
Issue: #2513 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=150310349
This commit is contained in:
parent
2fe478ad6a
commit
b98de975f1
2 changed files with 19 additions and 7 deletions
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue