Problem using MPMovieController in iPhone SDK 4.0

I used MPMoviePlayer to play a short video in my application without any problems in SDK 3.1.3. I made changes to the SDK 4 code, but the video does not play. I just get a black screen and sound. Apple Dev Center does not have sample code for this class for the latest SDK. The following is the code I'm using:

- (void)viewDidLoad {

    [super viewDidLoad];

        //videoPlayer is a MPMoviePlayerController object defined in the header file of the view controller

    if (videoPlayer == nil){
        NSString * videoPath = [[NSBundle mainBundle] pathForResource:@"myvideo" ofType:@"mp4"];
        if (videoPath == NULL){
            return; 
        }
        NSURL * videoURL = [NSURL fileURLWithPath:videoPath];

        videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
        videoPlayer.controlStyle = MPMovieControlStyleNone;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:movieController.moviePlayer];

        [videoPlayer play];
        [videoPlayer setFullscreen:YES];
        [self.view addSubview:videoPlayer.view];


    }

}

The above leads to simple reproduction of sound using a black screen. The notification is triggered correctly at the end of playback.

If the above didn't work, I even tried using the new MPMoviePlayerViewController class as follows:

- (void)viewDidLoad {

    [super viewDidLoad];
    NSString * videoPath = [[NSBundle mainBundle] pathForResource:@"myvideo" ofType:@"mp4"];

    if (videoPath == NULL){
        return; 
    }
    NSURL * videoURL = [NSURL fileURLWithPath:videoPath];

        //movieController is an MPMoviePlayerViewController object defined in the header file of view controller

    movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackFinished:) name:@"MPMoviePlayerPlaybackDidFinishNotification" object:movieController.moviePlayer];

    [movieController.moviePlayer setFullscreen:YES];
    [movieController.moviePlayer play];
    [self presentMoviePlayerViewControllerAnimated:movieController];
}

The same problem persists - I hear that the sound and notification at the end of playback are called as expected. However, I just see a black screen instead of a video.

, iTunes, iPod Touch .

- ?

+3
1

- , , , MPMoviePlayerController :

:

[videoPlayer play];

[videoPlayer setFullscreen:YES];

[self.view addSubview:videoPlayer.view];

:

[videoPlayer prepareToPlay];

[videoPlayer play];

[self.view addSubview:videoPlayer.view];

videoPlayer.view.frame = CGRectMake(0.0, 0.0, 480.0, 320.0); //this is explicitly added and solves the problem
+3

Source: https://habr.com/ru/post/1753025/


All Articles