I am having an Activity in which there is
VideoView -- Streams a video from a webserver.
Button -- Takes the user to the next activity to be shown.
When the application starts, VideoView is made to play the Video from a webserver.
Now assume
Total Video length is 60 Minutes
Current Video progress is 20 Minutes
Current Buffered progress 30 Minutes
Now when I click on the above mentioned Button which takes user to the next activity.
From that Activity if i press the back button, Previous Activity(with VideoView and Button) appears in front of the user. But when resumed all the Buffered Portion of the video is lost and hence the VideoView starts playing the video from the beginning which is really bad. <-- Actual Problem
Problem
When Activity is resumed back, the buffered portion of the video is lost and hence starts buffering it again. So how to overcome re-buffering the buffered portion of the Video ?
Even official Youtube android app. has the same problem.
Edit 1 :
I tried the below code in Activity but its not working.
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
videoView.suspend();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
videoView.resume();
}
Can anyone guide me regarding this problem ?. Or am I missing something to make this work perfectly ?
Current Workaround
I have saved the current playing position of the video in onPause()
method and in onResume()
method I have used that position to seek the video to that duration. This works fine. But the video buffering starts from the beginning tho it starts the video from the seek position.
Any help is deeply appreciated.
I found a solution fix it:
It work for me, i sure it help you
The problem with
videoView.resume()
inonResume()
can be seen here: VideoView.resume().VideoView.resume()
callsopenVideo()
which first releases any previous MediaPlayer instances and then starts a new one. I cannot see an easy way out of this.I see two possibilities:
Have fun! :)
try by adding above twomethods in your activity.
I've worked out a version that does not require a custom VideoView or manual configuration change handling. See Android VideoView orientation change with buffered video for an explanation.
You've mentioned two separate problems, and while I don't know how to keep the buffered video, You can still avoid starting from the beginning by calling
getCurrentPosition
in onPause andseekTo
on onResume. This call is asynchronous, but it might give you a partial solution.In onPause() function, instead of
try