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:

  1. 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" />
  2. If we are using a layout resource, we get hold of the VideoView from the layout:
    var videoView = FindViewById<VideoView>(Resource.Id.videoView); 
  3. Once we have ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.