开发者

VideoView in Android

开发者 https://www.devze.com 2023-02-01 13:26 出处:网络
I am using VideoView in Android for displaying streaming videos. While playing the videos if a user receives & disconnects the call ,the video starts playing from beginning instead of the behavior

I am using VideoView in Android for displaying streaming videos. While playing the videos if a user receives & disconnects the call ,the video starts playing from beginning instead of the behavior which should be that after the call disconnection ,the video should start playing from the same place when the call was received.

K开发者_如何转开发indly provide your suggestions/sample code if you have already implemented the same.


I have not tried this, but this is where I would start:

Step #1: In onStop(), call getCurrentPosition() on the VideoView and save the value.

Step #2: In onStart(), call getCurrentPosition() on the VideoView and compare it to the value from Step #1. If they differ (e.g., getCurrentPosition() is now 0), call seekTo(), supplying the value from Step #1.

Step #3: In onSaveInstanceState(), call getCurrentPosition() on the VideoView and store the value in the supplied Bundle.

Step #4: In onRestoreInstanceState(), obtain the value from Step #3 from the supplied Bundle and put it in the data member used by Step #1 and Step #2.

This should cover you for the relevant scenarios that might occur while the phone call is going on.


You probably should look at the life of an activity. Make sure you handle the onStart() and onStop() well, starting the video in the same place.

VideoView has an getCurrentPosition() and seekTo(), those should help to get the spot set right.

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号