Playing a video
Videos allow complex information to be presented to a user. This can just be a background, or it can be an information animation. Regardless of the exact reason, videos can enhance apps.
How to do it...
One of the simplest ways to display a video is to use a VideoView
instance, which wraps an underlying SurfaceView
and a MediaPlayer
:
The first thing we add to the layout is a
VideoView
instance, using either code or the layout resources:<VideoView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:id="@+id/videoView" />
If we are using a layout resource, we get hold of the
VideoView
from the layout:var videoView = FindViewById<VideoView>(Resource.Id.videoView);
Once we have the
VideoView
property, we can set the source of the video. This can either be from a remote source, or from a local resource, such as one of the app resources:var path = string.Format( "android.resource://{0}/{1}", PackageName...