Detect if Android SurfaceView draws / moves

I am using libvlc on and android app to play network stream; native code draws an image on the surface.

Suppose the video stops and I don’t have access to my own code, how can I determine if the SurfaceView is still moving (the video is not frozen)?

I tried getViewTreeObserver (). addOnDrawListener (); and getViewTreeObserver (). addOnPreDrawListener (); but they do not have the effect I'm looking for.

thanks

+7
android surfaceview vlc
source share
2 answers

You cannot get this information from SurfaceView, because SurfaceView itself does not know.

The task of SurfaceView is to customize Surface and create a hole in the View layout that you can view. Once he has done this, he is no longer involved in the process of displaying the video. Content is transferred from the decoder to the surface, which is controlled by SurfaceFlinger (system graphics layout).

This, for example, is how DRM video works. The application that plays the video does not have access to DRM-protected video frames. (Neither SurfaceFlinger, actually, but it's a longer story.)

The best way to find out if the content still reaches is to ask the source of the video if it still sends you the content. Another approach would be to change the SurfaceView to a TextureView and provide the onSurfaceTextureUpdated() callback method.

+6
source share

I'm not sure what exactly you are trying to achieve here, but you can see if the surface view renders rendering or not through the implementation of the SurfaceHolder.Callback interface, which gives you access to the following methods:

  • On Surface Created - This is called immediately after the surface was first created.

  • On Surface Changed - This is called immediately after any structural changes have been made to the surface (format or size).

  • On Surface Destroyed - This is called immediately before the destruction of the surface.

Take a look at the documentation to view the surface. For SurfaceHolder, see the link. In principle, to know

+1
source share

All Articles