【发布时间】:2018-09-10 21:55:51
【问题描述】:
我想创建一个具有暂停和恢复功能的视频视图。因此,为了节省当前时间,我将共享首选项用作临时存储。但在调试时,它在 onPause()、onStop()、onResume()、onStart() 中完美运行。但是当安装在设备中时,视频每次都是从头开始。如何解决这个问题?
@Override
protected void onResume() {
super.onResume();
resumeVideo();
}
@Override
protected void onPause() {
super.onPause();
saveCurrentTime();
}
@Override
protected void onStop() {
super.onStop();
saveCurrentTime();
}
@Override
protected void onRestart() {
super.onRestart();
resumeVideo();
}
//......to save current duration in shared preference
public void saveCurrentTime(){
String current_time = String.valueOf(vdoView.getCurrentPosition());
sharedPreference.putValue(this,Constants.SP_NAME,Constants.CURRENT_TIME,current_time);
}
//to resume video from given time
public void resumeVideo(){
String time = sharedPreference.getValue(this, Constants.SP_NAME, Constants.CURRENT_TIME);
if(!sharedPreference.getValue(this,Constants.SP_NAME,Constants.CURRENT_TIME).equals("")) {
int t = Integer.parseInt(time);
vdoView.seekTo(t);
}
vdoView.start();
}
【问题讨论】:
-
它只是关于 onPause() 怎么样 onStop(),onDestroy()
-
应用程序在调试时运行完美,但直接在设备或模拟器上运行时无法恢复
-
你试过我的答案了吗?
-
试过但没用
标签: android android-debug