Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayer - black screen - iOS 5 - no video playing

In iOS 4 this Code worked to play a movie:

-(IBAction)playMovie:(id)sender
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testbild1" ofType:@"m4v"]];
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

    [testview addSubview:moviePlayer.view];
    [self.view addSubview:testview];
    //[self.view addSubview:moviePlayer.view];
    //[moviePlayer setFullscreen:YES animated:YES];
}  

- (void)moviePlaybackComplete:(NSNotification *)notification  
{  
    MPMoviePlayerController *moviePlayerController = [notification object];  
    [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                    name:MPMoviePlayerPlaybackDidFinishNotification  
                                                  object:moviePlayerController];  

    [moviePlayerController.view removeFromSuperview];  
    //[moviePlayerController release];  
}  

Now, I only get a blackscreen. No controls, nothing. Video path is correct, I tested that. If I add just a white Subview by button click, it works. So the method is called.

Thanks in advance!

like image 977
DAS Avatar asked Dec 10 '22 05:12

DAS


2 Answers

I have solved the issue by putting in the .h file

MPMoviePlayerController *moviePlayer;

iOS 5 with ARC works differently than iOS 4.

The .m file must be:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
like image 155
TheMiloNet Avatar answered Dec 22 '22 15:12

TheMiloNet


If you are on iOS 5.0 or 5.1, check your moviePlyer has a setting like below.

[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

If so, when you set [moviePlayer setFullScreen:YES animated:YES]; then MPMoviePlayerPlaybackDidFinishNotification notification will be called instead of being called MPMoviePlayerWillExitFullscreenNotification or MPMoviePlayerDidExitFullscreenNotification

like image 22
tigmi Avatar answered Dec 22 '22 15:12

tigmi