Book Image

iOS Development with Xamarin Cookbook

By : Dimitrios Tavlikos (USD)
Book Image

iOS Development with Xamarin Cookbook

By: Dimitrios Tavlikos (USD)

Overview of this book

Table of Contents (22 chapters)
iOS Development with Xamarin Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Playing videos


In this recipe, we will learn how to display a video player interface and play video files.

Getting ready

Create a new Single View Application in Xamarin Studio and name it PlayVideoApp.

How to do it...

Perform the following steps:

  1. Add a button to the main view of the controller.

  2. Add a video file to the project and set its Build Action to Content.

  3. Add the following code to the ViewDidLoad method of the controller class:

    this.moviePlayer = new MPMoviePlayerController(NSUrl.FromFilename("video.mov"));
    this.moviePlayer.View.Frame = new RectangleF(0f, 20f, this.View.Frame.Width, 320f);
    this.View.AddSubview(this.moviePlayer.View);
    this.playbackStateChanged = MPMoviePlaybackController.Notifications.ObservePlaybackStateDidChange(this.MoviePlayer_PlaybackStateChanged);
    this.finishedPlaying = MPMoviePlaybackController.Notifications.ObservePlaybackDidFinish(this.MoviePlayer_FinishedPlayback);
    this.btnPlayVideo.TouchUpInside += delegate {
      this.moviePlayer.Play();
    } ;
  4. Enter the following methods...