Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if Android SurfaceView is drawing/moving

I'm using libvlc on and android app to play a network stream; the native code draws the image on a surfaceview.

Let's assume the video stops and I have no access to the native code, how can I detect 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

like image 686
Ambi Avatar asked Mar 13 '15 23:03

Ambi


2 Answers

You can't get that information from the SurfaceView, because the SurfaceView itself does not know.

The SurfaceView's job is to set up the Surface, and create a hole in the View layout that you can see through. Once it has done these things, it is no longer actively involved in the process of displaying video. The content flows from the decoder to the Surface, which is managed by SurfaceFlinger (the system graphics compositor).

This is, for example, how DRM video works. The app "playing" the video has no access to DRM-protected video frames. (Neither does SurfaceFlinger, actually, but that's a longer story.)

The best way to know if content is still arriving is to ask the video source if it is still sending you content. Another approach would be to change your SurfaceView to a TextureView, and provide an onSurfaceTextureUpdated() callback method.

like image 86
fadden Avatar answered Oct 12 '22 23:10

fadden


I am not sure what exactly what you are trying to achieve here but you can see if surface view is rendering or not through implementing an interface called SurfaceHolder.Callback which gives you access to the following methods,

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

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

  3. On Surface Destroyed - This is called immediately before a surface is being destroyed.

Take a look at the documentation for surface view. For SurfaceHolder take a look at this link. Basically in order to know

like image 33
Ahmed Avatar answered Oct 12 '22 23:10

Ahmed