Embed Video In App


I have to embed a video from my resources in a UIView.
So in first I add my video to my resources folder and put his build action to "content".
My video is in MP4 format.

Then I created this func which is call in ViewDidLoad.

`void Video()
string fileName = "Resources/Movies/menu.mp4";
string locallUrl = Path.Combine(NSBundle.MainBundle.BundlePath, fileName);

        NSUrl url = NSUrl.FromFilename("menu.mp4");

        _player = new MPMoviePlayerController(url);
        _player.View.Frame = VideoView.Bounds;

        _player.ControlStyle = MPMovieControlStyle.None;

And then I called _player.Play() in ViewDidAppear.

But nothing happen.

I think i missed something but I don't know what.

Thank's in advance,




  • NuninzNuninz USMember ✭✭

    Did you check the size of that _player.View frame? Perhaps it's set to zero so you don't see anything. Other option is looking at MPMoviePlayerController logs. If it's not playing it should throw some errors

  • Thank's for your answer, but the frame is not set to zero.
    For the second option, how can I get some logs for the MPMoviePlayerController? because I have nothing in the application output...

  • LarryOBrienLarryOBrien USXamarin Team Xamurai
    edited September 2016

    I notice that your filename variable is set two different ways. That may be it. If you have the .mp4 in the Resources/ folder, you should be able to load it with the NSUrl.FromFilename( Path.Combine (... technique. I have attached a solution that demonstrates the technique.

           var fname = Path.Combine (NSBundle.MainBundle.BundlePath, "rocket_exploding.mp4");
           var movieUrl = NSUrl.FromFilename (fname);
    #if DEBUG
            var confirmFile = File.Exists (fname);
            player = new MPMoviePlayerController (movieUrl);
Sign In or Register to comment.