Workaround to supply file extension to ExoPlayer
This commit is contained in:
parent
a5f422942b
commit
54721ad7b1
|
@ -371,9 +371,10 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
|
||||||
);
|
);
|
||||||
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, httpDataSourceFactory);
|
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, httpDataSourceFactory);
|
||||||
Uri uri = Uri.parse(url);
|
Uri uri = Uri.parse(url);
|
||||||
if (uri.getPath().toLowerCase().endsWith(".mpd")) {
|
String extension = getLowerCaseExtension(uri);
|
||||||
|
if (extension.equals("mpd")) {
|
||||||
mediaSource = new DashMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
mediaSource = new DashMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
||||||
} else if (uri.getPath().toLowerCase().endsWith(".m3u8")) {
|
} else if (extension.equals("m3u8")) {
|
||||||
mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
mediaSource = new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
||||||
} else {
|
} else {
|
||||||
mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
||||||
|
@ -381,6 +382,16 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
|
||||||
player.prepare(mediaSource);
|
player.prepare(mediaSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getLowerCaseExtension(Uri uri) {
|
||||||
|
// Until ExoPlayer provides automatic detection of media source types, we
|
||||||
|
// rely on the file extension. When this is absent, as a temporary
|
||||||
|
// workaround we allow the app to supply a fake extension in the URL
|
||||||
|
// fragment. e.g. https://somewhere.com/somestream?x=etc#.m3u8
|
||||||
|
String fragment = uri.getFragment();
|
||||||
|
String filename = fragment != null && fragment.contains(".") ? fragment : uri.getPath();
|
||||||
|
return filename.replaceAll("^.*\\.", "").toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
public void setClip(final Long start, final Long end, final Result result) {
|
public void setClip(final Long start, final Long end, final Result result) {
|
||||||
if (state == PlaybackState.none) {
|
if (state == PlaybackState.none) {
|
||||||
throw new IllegalStateException("Cannot call setClip from none state");
|
throw new IllegalStateException("Cannot call setClip from none state");
|
||||||
|
|
Loading…
Reference in New Issue