我正在设计一个视频播放器应用程序,当用户通过onbackpressed()或通过intentials按钮离开它使用另一个应用程序并可能稍后回来时,我似乎对该活动有问题。当用户转到另一个活动时,我希望视频播放暂停,当此活动再次获得焦点时,从暂停的位置完全恢复…我尝试用这些方法覆盖,但没有成功,请帮助。。。
public class video_player extends AppCompatActivity {
VideoView main_screen;
ListView filelist;
DrawerLayout mydrawer;
MediaController mc;
TextView mytext;
String video_name;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Assign value to media controller
mc=new MediaController(this);
//Define VideoView
main_screen = (VideoView) findViewById(R.id.videoplayer);
Uri uri= Uri.parse(first);
main_screen.setVideoURI(uri);
mc.setAnchorView(main_screen);
mc.setMediaPlayer(main_screen);
main_screen.setMediaController(mc);
//Start playback
main_screen.start();
}
//method to pause video when user goes to another activity
protected void onSaveInstanceState(Bundle savedInstanceState){
//Video can be paused but how do i save this to the outstate Bundle??
super.onSaveInstanceState(savedInstanceState);
}
//method to resume playback onrestore but am clueless
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState();
}
@Override
protected void onPause(){
main_screen.pause();
super.onPause();
}
@Override
protected void onResume(){
main_screen.resume();
super.onResume();
}
}
感谢您花时间阅读此文,非常感谢您的帮助}
2条答案
按热度按时间ojsjcaue1#
在类中声明一个整数,该整数将在onpause()方法中指定视频搜索栏的当前位置,并在onresume()方法中使视频搜索到该整数,如下所示。。。
每当活动被发送到后台时,这种方法就起作用
lnxxn5zx2#