Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues playing a video with MonoTouch

I'm having a few issues playing a video in MonoTouch. From what I can find there are two different approaches to take. Both result in the audio being played but no video. I'm betting I'm missing something simple so any help would be great.

Attempt one - taken from MT documentation

moviePlayer = new MPMoviePlayerController(new NSUrl("test.mp4"));  
moviePlayer.Play();

Attempt two

moviePlayer = new MPMoviePlayerViewController(new NSUrl("test.mp4")); 
this.PresentMoviePlayerViewController(moviePlayer);

Thanks

like image 713
James Antrobus Avatar asked Jan 22 '11 16:01

James Antrobus


1 Answers

From looking at the documentation, you need to add the MPMoviePlayerController to a view, otherwise the video will no know where to play.

Your second attempt looks a little better, are you calling the play method on the moviePlayer (note this is a MPMoviePlayerViewController) MPMoviePlayerController (named MoviePlayer)?

For what it's worth, I can get;

moviePlayerController = new MPMoviePlayerViewController(new NSUrl("test.mp4")); 
this.PresentMoviePlayerViewController(moviePlayerController);

working with no issues on a sample iPad app. Are you sure your test.mp4 is...

  1. Encoded correctly
  2. Included in the project
  3. Video's build action is set to content

Documentation for MPMoviePlayerController: http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html

Documentation for MPMoviewPlayerViewController: http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerViewController_class/Reference/Reference.html#//apple_ref/occ/cl/MPMoviePlayerViewController

like image 98
chrisntr Avatar answered Oct 18 '22 05:10

chrisntr