Why won't my MPMoviePlayerController play?

I am trying to get the base .mov video file to play using the code below, but when the button that I assigned the action is pressed, the only thing that appears is a black frame, but the video does not play, Any help is appreciated. Thank.

@implementation SRViewController

-(IBAction)playMovie{
    NSString *url = [[NSBundle mainBundle]
                     pathForResource:@"OntheTitle" ofType:@"mov"];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
                                       initWithContentURL: [NSURL fileURLWithPath:url]];

    // Play Partial Screen
    player.view.frame = CGRectMake(10, 10, 720, 480);
    [self.view addSubview:player.view];

    // Play Movie
    [player play];
}

@end
+5
source share
1 answer

Assumed Prerequisite: Your project uses ARC .

MPMoviePlayerController , ARC , . , , MPMoviePlayerController playMovie.

, SRViewController .

:

@instance SRViewController

   [...]

   @property (nonatomic,strong) MPMoviePlayerController *player;

   [...]

@end

:

@implementation SRViewController

   [...]

    -(IBAction)playMovie
    {
        NSString *url = [[NSBundle mainBundle]
                         pathForResource:@"OntheTitle" ofType:@"mov"];
        self.player = [[MPMoviePlayerController alloc]
                                           initWithContentURL: [NSURL fileURLWithPath:url]];

        // Play Partial Screen
        self.player.view.frame = CGRectMake(10, 10, 720, 480);
        [self.view addSubview:self.player.view];

        // Play Movie
        [self.player play];
    }

    [...]

@end
+13

All Articles