Issue
I've a url of the form http://x.x.x:80/movie/HqZqUt3I7B/QhGtliO2V4/xxxx.mp4?play_token=6nsYOBGUKj from where I want to fetch video and display it in exoplayer. I confirmed that url is perfectly working by putting that url in VLC Network Stream. But the same url is not working in exoplayer. Here's my exoplayer initializing code.
private fun initializePlayer() {
if (url.isNotEmpty()){
player = SimpleExoPlayer.Builder(this).build()
binding.videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FILL
player.videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT
binding.videoView.player = player
val mediaItem: MediaItem = MediaItem.fromUri(url)
Log.d("testurl", url)
player.setMediaItem(mediaItem)
player.playWhenReady = playWhenReady
player.seekTo(currentWindow, playbackPosition)
player.prepare()
player.addListener(this)
} else {
Toast.makeText(this, "Unable to play the video!", Toast.LENGTH_SHORT).show()
}
}
I've also implemented OnPlayerError listener to catch the error.
override fun onPlayerError(error: PlaybackException) {
super.onPlayerError(error)
if (error.message!=null) {
Log.d("testmediaerror", "${error.errorCodeName} ${error.message}")
} else {
Log.d("testmediaerror", error.errorCodeName)
}
}
So, with this code if block in OnPlayerError was executed and it displayed the error as D/testmediaerror: ERROR_CODE_IO_BAD_HTTP_STATUS Source error. It is also necessary to mention that my server is returning the video with status code 302.
Solution
Ask the server for the file and then follow HTTP 302 redirect - this will result in that actual URL and HTTP 200 when fetching it. In Exoplayer, there's also a config allowCrossProtocolRedirects (it usually not permits redirects from eg. HTTPS to HTTP ...but it should support common redirects).
Answered By - Martin Zeitler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.