2011-10-28 57 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