O'Reilly logo

Xamarin Mobile Development for Android Cookbook by Matthew Leibowitz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required