2012-09-28 37 views
0

我用下面的代碼來播放電影在iPad 1上運行iOS6的無畫面:的MPMoviePlayerController:聲音,但在全屏模式下

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myMovie.mov" ofType:@""]]; 
    self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayBackDidFinish:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:self.moviePlayer]; 

    // Use the new 3.2 style API 
    self.moviePlayer.controlStyle = MPMovieControlStyleDefault; 

    [self.moviePlayer prepareToPlay]; 

    self.moviePlayer.view.frame = CGRectMake(0, 0, 1024, 768); 

    [self.uiView addSubview:self.moviePlayer.view]; 

    //[self.moviePlayer setFullscreen:YES animated:YES]; 

    [self.moviePlayer play]; 

這工作。

但是,如果我取消註釋行setFullscreen,我得到的電影音頻,但有一個完全黑屏,沒有圖片。

我試過改變幾行的順序,特別是play調用和setFullscreen調用,沒有任何效果。

更新

這個問題似乎是直接相關的:

MPMoviePlayerController in full screen issue (showing blank black screen)

+0

這個問題並非真正的答案,但我已切換到MPMoviePlayerViewController,並且它對全屏視頻效果很好。 – occulus

回答

0

首先是改變這一行:
[[NSBundle mainBundle] pathForResource:@"myMovie.mov" ofType:@""]到:
[[NSBundle mainBundle] pathForResource:@"myMovie" ofType:@"mov"],然後再試一次

+0

沒有變化,但如果這確實影響了任何事情,我會感到驚訝。它有助於解決您遇到的問題嗎? – occulus

0

使用此作爲它爲我工作:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myMovie" ofType:@"mov"]]; 
MPMoviePlayerViewController *movieView = [[MPMoviePlayerViewController alloc]initWithContentURL:url]; 
movieView.moviePlayer.scalingMode = MPMovieScalingModeFill; 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
     [movieView.moviePlayer.view setFrame:CGRectMake(0,0,480,320)]; 
else 
     [movieView.moviePlayer.view setFrame:CGRectMake(0,0,1024,768)]; 
movieView.moviePlayer.view.userInteractionEnabled = FALSE; 
movieView.moviePlayer.controlStyle=0; 
[movieView setFullscreen:YES]; 
self.view=movieView.view; 
+0

謝謝!有趣。我試過你的代碼,而這個似乎有所作爲的位是最後一行 - 直接替換當前視圖的電影播放器​​視圖的設置使視頻可見。不幸的是,電影播放器​​顯示了電影的一面! – occulus

相關問題