Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top