Exoplayer Error In Recyclerview, Source Error None Of The Available Extractors
Solution 1:
You need to modify your createUrlMediaSource
privatefuncreateUrlMediaSource(url: String, context: Activity): MediaSource {
val userAgent = Util.getUserAgent(context, context.getString(R.string.about))
return ProgressiveMediaSource
.Factory(DefaultDataSourceFactory(context, userAgent), DefaultExtractorsFactory())
.createMediaSource(Uri.parse(url))
}
as stated in https://exoplayer.dev
DashMediaSource
for DASH.SsMediaSource
for SmoothStreaming.HlsMediaSource
for HLS (this is your format => .m3u8).ProgressiveMediaSource
for regular media files.
So you need to replace your function to this:
privatefuncreateUrlMediaSource(url: String, context: Activity): MediaSource {
val userAgent = Util.getUserAgent(context, context.getString(R.string.about))
return HlsMediaSource
.Factory(DefaultDataSourceFactory(context, userAgent), DefaultExtractorsFactory())
.createMediaSource(Uri.parse(url))
}
Solution 2:
I don't think m3u8 is a video format but rather a playlist format. I think Exoplayer is lower level than handling playlists; probably you need to read the m3u8 file yourself and then pass in the links in the playlist yourself.
Luckily the file format isn't complicated and it shouldn't be too difficult to parse. It seems it's pretty well documented. There's even some examples on Wikipedia: https://en.wikipedia.org/wiki/M3U
Solution 3:
On Android 4.1+, you can use this library https://github.com/brianwernick/ExoMedia/ . The example mentioned on the Read-me page should be sufficient to get you started. I have reproduced that code snippet with a few additions/modifications.
privatevoidsetupVideoView() {
EMVideoView emVideoView = (EMVideoView)findViewById(R.id.video_play_activity_video_view);
emVideoView.setOnPreparedListener(this);
//Enter your m3u8 URL below
emVideoView.setVideoURI(Uri.parse("http://SOMESERVER/playlist.m3u8"));
}
@OverridepublicvoidonPrepared(MediaPlayer mp) {
//Starts the video playback as soon as it is ready
emVideoView.start();
}
@OverridepublicvoidonPause() {
super.onPause();
//Pause Video Playback
emVideoView.pause();
}
Solution 4:
For streaming .m3u8 file use below code while initializing Exoplayer:-
BandwidthMeterbandwidthMeter=newDefaultBandwidthMeter();
TrackSelection.FactoryvideoTrackSelectionFactory=newAdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelectortrackSelector=newDefaultTrackSelector(videoTrackSelectionFactory);
videoPlayer = ExoPlayerFactory.newSimpleInstance(context,trackSelector);
HandlermHandler=newHandler();
StringuserAgent= Util.getUserAgent(context, "Exo Player");
DataSource.FactorydataSourceFactory=newDefaultHttpDataSourceFactory(
userAgent, null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
1800000,
true);
HlsMediaSourcemediaSource=newHlsMediaSource(Uri.parse(mediaUrl),dataSourceFactory, 1800000,mHandler, null);
if (mediaUrl != null) {
videoPlayer.prepare(mediaSource);
videoPlayer.setPlayWhenReady(true);
}
Post a Comment for "Exoplayer Error In Recyclerview, Source Error None Of The Available Extractors"