Android's MediaPlayer setSurface while on paused state

£可爱£侵袭症+ 提交于 2019-12-04 06:50:33

it seems your problem is with this specific video, more keyframes will help the player to resume the playing more accurately.

try to re-encode again, with ffmpeg and libx264 try adding these parameters:

-g=25 -keyint_min=25

Try passing the position of your MediaPlayer from activity A to Activity B using Intent.putExtra(). So Basically in Activity A where you call intent to start activity B, you would do this:

 public void onClick(View v) {     
    Log.e("WHATEVER", ">>> pause video at " + MyApplication.getMediaPlayer().getCurrentPosition());
    MyApplication.getMediaPlayer().pause();
    int position = MyApplication.getMediaPlayer().getCurrentPosition(); //new line added
    Intent intent = new Intent(getActivity(), ActivityB.class);
    intent.putExtra("position", position); //another new line of code
    startActivity(intent);
}

Now in Activity B seek to the position where mediaplayer was paused before calling start, like this:

@Override
    public void onSurfaceTextureAvailable(SurfaceTexture surface, int w, int h) {
        MediaPlayer mediaPlayer = MyApplication.getMediaPlayer();
        mediaPlayer.setSurface(new Surface(surface));

        Log.e("WHATEVER", ">>> resume video at " + mediaPlayer.getCurrentPosition());
        mediaPlayer.seekTo(getIntent().getExtras().getInt("position"));// new line of code
        mediaPlayer.start();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!