2012-06-29 41 views
0

嗯,我可以找到關於相同或相似問題和答案的許多問題......但是,沒有任何東西可以幫助我。只有當我不使用屬性「controlStyle」作爲「MPMovieControlStyleFullscreen」時,「完成」按鈕才起作用。我想這樣..當全屏模式下,MPMoviePlayerController中的「完成」按鈕不起作用

MPMoviePlayerController *mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]]; 
    mpMoviePlayerController.controlStyle = MPMovieControlStyleNone; 
    [mpMoviePlayerController setUseApplicationAudioSession:NO]; 
    [mpMoviePlayerController setScalingMode:MPMovieScalingModeAspectFit]; 
    [mpMoviePlayerController setFullscreen:YES animated:YES]; 
    [mpMoviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)]; 

    [[globalSingleton paintingView] addSubview:mpMoviePlayerController.view]; 

    [mpMoviePlayerController prepareToPlay]; 
    [mpMoviePlayerController play]; 

    mpMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen; 

或這樣..

MPMoviePlayerController *mp; 
    MPMoviePlayerViewController *mpVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]]; 
    mp = [mpVC moviePlayer]; 
    mp.controlStyle = MPMovieControlStyleFullscreen; 
    mp.fullscreen = NO; 
    mp.useApplicationAudioSession = NO; 
    mp.view.frame = CGRectMake(0, 0, 1024, 768); 

    [[globalSingleton paintingView] addSubview:mp.view]; 

([globalSingleton paintingView]只是爲代表的主要觀點。我已經簽有它沒問題。)

請分享你對這個問題的瞭解。 Thx提前!

回答

3

根據你的代碼,它在我看來你的意圖是讓一個全屏電影播放器​​接管屏幕。在這種情況下,你可能使用過的MPMoviePlayerViewController更好,但你需要使用這樣的當前視圖控制器,將其作爲一個模式視圖控制器:

MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:someVideoURL]; 
movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 

// Self is the UIViewController you are presenting the movie player from. 
[self presentMoviePlayerViewControllerAnimated:movieViewController]; 

「完成」按鈕,應在此正常工作case,並關閉模式MPMoviePlayerViewController

另一方面,如果您更感興趣的是從當前視圖層次結構中添加動畫的動畫,那麼以下是我已經完成的一個示例這個:

我還發現設置MPMoviePlayerController的controlStyle p roperty到MPMovieControlStyleFullscreen有相同的結果 - 「完成」按鈕沒有關閉MPMoviePlayerController。當我將其更改爲MPMovieControlStyleDefault時,它按預期工作。但是,就我而言,我將MPMoviePlayerController的視圖作爲縮略圖大小的子視圖添加到當前顯示的UIViewController的視圖中。我最初將MPMoviePlayerController的controlStyle設置爲MPMovieControlStyleNone。我在縮略圖大小的電影播放器​​視圖之上有一個自定義的UIButton,並且在按鈕的操作方法中,我將MPMoviePlayerController的controlStyle更改爲MPMovieControlStyleDefault,然後調用setFullscreen:animated:將動畫播放器視圖動畫到全屏模式。然後,點擊「完成」按鈕,將我的UIViewController視圖的縮略圖大小的子視圖中的播放器恢復到原位。這裏有一個例子:

MPMoviePlayerController的初始實例:

// My moviePlayerController is a property 
self.moviePlayer = [[MPMoviePlayerController alloc] initWithURL:videoURL]; 
moviePlayer.controlStyle = MPMovieControlStyleNone; 
moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
moviePlayer.shouldAutoplay = NO; 


// Add the moviePlayer's view as a subview of a my UIViewController's view. 
moviePlayer.view.frame = CGRectMake(20, 20, 160, 90); 
[self.view addSubview:moviePlayer.view]; 

注:我還添加了一個自定義的UIButton我moviePlayer的觀點之上(調用全屏播放),並設置它的行動呼籲下面的方法:

- (void)buttonAction:(UIButton *)sender 
    { 
     self.moviePlayer.controlStyle = MPMovieControlStyleDefault; 
     [self.moviePlayer setFullscreen:YES animated:YES]; 
     [self.moviePlayer play]; 
    } 

注:我也觀察和處理,我設定的MPMoviePlayerWillExitFullscreenNotification controlStyle返回到MPMovieControlStyleNone。

相關問題