How to detach / release surface view from android media plan

I have a media player instance running in the background. In my main activity I have a surface survey.

When the action starts and the surface view is created, I contact the service and set the display surface of the media planner to the surface view from my main action. I do this with mPlayer.setSurface(sv.getHolder().getSurface());

The video is displayed, and everything still works. When my surface vision is destroyed, in the surfaceDestroyed() I try to separate the surface image from the media mPlayer.setSurface(null); calling mPlayer.setSurface(null); . The problem is that when I do this, I get an error message from the media player (error code 1).

So my question is that after I created the MediaPlayer object and I set the viewview with mPlayer.setSurface(sv.getHolder().getSurface()); Is there a way to free or separate this surface representation without stopping or reinitializing the media planner object?

Thanks in advance.

+6
source share
1 answer

You can avoid pausing playback when the user moves. This will help you continue playing. But there is another problem: when your activity / fragment, separated from the SurfaceView window, collapsed. This means that you must reinitialize the media player with the recreated instance of SurfaceView when the user returns to your application.

0
source

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


All Articles