【问题标题】:how to achive Video View's pause and resume functionality in android?如何在 android 中存档视频视图暂停和恢复功能?
【发布时间】: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


【解决方案1】:

很明显,您的额外处理程序在意外时间用 0 覆盖了首选项,因为 vdoView 已更改状态。

删除您的 onStop()onRestart()(和 onDestroy())处理程序。您只需要onPause()onResume()。有关详细信息,请参阅the documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    相关资源
    最近更新 更多