android: videoview history/bookmark

橙三吉。 提交于 2019-12-11 08:52:27

问题


I have a videoplayer application. Suppose the user has played a video and after playing half of the video, the user pressed the back button or exists the application. I want that position to be remembered so that the next time, the user plays the same video, the video starts from exactly the same position from where it was left.

Any ideas in this regard? Thanks much


回答1:


First, you will need to store this data in some database, but it's quite simple.

Now, you should add a check in the onPause() or onDestroy() method of your activity, which gets the position from the videoview:

public void onPause() {
// ....
   int position = myVideoView.getCurrentPosition();
// store the position and file name (you should have it from before)
}

When you play a video, set the current position as stored before:

private void dummyPlayVideo(String fileName) {
// ....
    int position = getSavedPositionOfVideo(fileName); // your method
    myVideoView.seekTo(position);
}


来源:https://stackoverflow.com/questions/7860855/android-videoview-history-bookmark

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!