Android MediaPlayer streaming video setSurface jump back

I am developing an Android application that can play streaming video and navigate through it when playing video in the background.

Video playback on the Service, and to watch the video, I installed the surface MediaPlayerin SurfaceTextureto TextureView. There is no problem, it works great.

The problem occurs when the user minimizes the player (no problem) and wants to open it again. Here, when I install Surface again on MediaPlayer, the video jumps one or two seconds back and continues to play fine. Here is the code when I set the surface on MediaPlayer:

    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
      surfaceTexture = new Surface(surface);

      if (myMusicService != null) {
        myMusicService.getMediaPlayer().setSurface(surfaceTexture);
      }

}

I tried with SurfaceViewtoo (instead of a TextureView) with the same result.

Any ideas?

Thanks,

+4

Source: https://habr.com/ru/post/1626327/


All Articles