In this recipe, we will learn how to display a video player interface and play video files.
Perform the following steps:
Add a button to the main view of the controller.
Add a video file to the project and set its Build Action to Content.
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(); } ;
Enter the following methods...