Reputation: 934
So I was trying to play some HLS with ExoPlayer 2. It was working fine but suddenly I have 403 error. When I ran the url ("http://open.live.bbc.co.uk/mediaselector/5/redir/version/2.0/vpid/b0bbnbp9/mediaset/audio-syndication/proto/http") on safari it's working fine but not when I try it with the Android app.
val bandwidthMeter = DefaultBandwidthMeter()
val extractorsFactory = DefaultExtractorsFactory()
val trackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector = DefaultTrackSelector(trackSelectionFactory)
val userAgent: String = Util.getUserAgent(applicationContext, "mediaPlayerSample")
val httpDataSourceFactory = DefaultHttpDataSourceFactory(
userAgent,
null,
DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS,
DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS,
true
)
val mediaSource = ExtractorMediaSource.Factory(httpDataSourceFactory).setExtractorsFactory(extractorsFactory).createMediaSource(Uri.parse(url))
mPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector)
mPlayer.seekTo(contentPosition)
mPlayer.prepare(mediaSource)
mPlayer.playWhenReady = true
Error Message:
07-24 12:19:41.784 28569-29226/com.twoversion E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 403
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:211)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.checkOpened(DataSourceInputStream.java:102)
at com.google.android.exoplayer2.upstream.DataSourceInputStream.open(DataSourceInputStream.java:65)
at com.google.android.exoplayer2.upstream.ParsingLoadable.load(ParsingLoadable.java:129)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:308)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Upvotes: 1
Views: 3981
Reputation: 199
Your code seem's perfect, Just you need to change your code:
val mediaSource = ExtractorMediaSource.Factory(httpDataSourceFactory).setExtractorsFactory(extractorsFactory).createMediaSource(Uri.parse(url))
To, Update below code:
HlsMediaSource hlsMediaSource = new HlsMediaSource(Uri.parse(url),httpDataSourceFactory, 1800000,new Handler(), null);
mPlayer.prepare(hlsMediaSource)
Upvotes: 1
Reputation: 1037
The player is giving a source error as the url you are giving to the player is not a valid hls url.
Safari is able to play the file because it can figure out the actual redirect url and play that.
The url you are giving is actually redirecting to :
This is a valid hls url (has a m3u8 file). Try playing this on exoplayer and it should work
EDIT:
you can enable following of cross-protocol redirects in ExoPlayer by passing allowCrossProtocolRedirects=true to the DefaultUriDataSource constructor.
Upvotes: 0