Play video in iOS app: audio but no picture

I want a short video to play in my iphone application. When I use the code below, I only hear audio and see the normal view of the application. I want the video to play on top of this view. What can I do about this?

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"LEADER" ofType:@"mov"];
    NSURL  *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];
+3
source share
3 answers

Do not mix MPMoviePlayerControllerand MPMoviePlayerViewController. When you use MPMoviePlayerController, use it like this (usually for embedded videos on iPad):

MPMoviePlayerController *player =
        [[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view setFrame: myView.bounds];  // player frame must match parent's
[myView addSubview: player.view];
// ...
[player play];

When you use MPMoviePlayerViewController, transfer the video with presentMoviePlayerViewControllerAnimated:(usually for full-screen videos).

+4
source
MPMoviePlayerController *player =
        [[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view.frame = self.view.frame];
[self.view addSubview: player.view];
// ...
[player play];
0
source

, ,

 - (void) playMovie {
    NSURL *url = [NSURL URLWithString: 
        @"http://www.example.com/video.mp4"];
    MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] 
        initWithContentURL:url];

    self.mc = controller; //Super important
    controller.view.frame = self.view.bounds; //Set the size

    [self.view addSubview:controller.view]; //Show the view
    [controller play]; //Start playing
}

@property (nonatomic,strong) MPMoviePlayerController* mc;

0

All Articles