2011-10-28 68 views
4

在iOS 4的今典合作,播放电影:MPMoviePlayer - 黑屏 - iOS 5的 - 没有视频播放

-(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]; 
} 

现在,我只得到一个blackscreen。没有控制,没有。视频路径是正确的,我测试了这一点。如果我通过按钮点击添加一个白色的子视图,它就可以工作。所以这个方法被调用。

在此先感谢!

回答

13

我已经投入.h文件解决问题

MPMoviePlayerController *moviePlayer; 

的iOS 5与ARC工作方式是不同的iOS 4

.m文件必须是:

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
+0

我做,我这样说是相同的(但在其他项目中)有意和完美地工作。所以我认为就是这样。感谢您的贡献。 – DAS

+1

这不适用于我 – ios

+0

这可以与PhoneGap一起使用吗?我不确定如何/在哪里实施使用该框架 – bafromca

1

如果您使用的是iOS 5.0或5.1,请检查您的moviePlyer是否具有如下设置。

[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

如果是这样,当你设置[moviePlayer setFullScreen:YES animated:YES]; 然后MPMoviePlayerPlaybackDidFinishNotification通知将被调用,而不是被称为MPMoviePlayerWillExitFullscreenNotification或MPMoviePlayerDidExitFullscreenNotification