Custom video controls
The VideoView
is great for displaying videos with a basic set of controls; however, we may require more flexibility and control over how the video is played.
How to do it...
We can play a video onto a SurfaceView
using a MediaPlayer
instance if we need fine control over what we can do or if we want custom video controls:
First, when using a
SurfaceView
instance, we need to implement theISurfaceHolderCallback
interface, ensuring that we keep track of the surface:public class MainActivity : Activity, ISurfaceHolderCallback { private ISurfaceHolder surfaceHolder; public void SurfaceChanged( ISurfaceHolder holder, Format format, int width, int height) { } public void SurfaceCreated(ISurfaceHolder holder) { surfaceHolder = holder; } public void SurfaceDestroyed(ISurfaceHolder holder) { surfaceHolder = null; } }
Then, in the
OnCreate()
method, we want to get hold of theISurfaceHolder
instance using theHolder
property of theSurfaceView
instance...