2011-01-19 195 views
1

我有一個作爲viewControllers層次結構構建的應用程序。在橫向(iPhone)全屏播放視頻

關於視圖控制器是爲應用程序的「視頻部分」。

該應用僅設計爲肖像,但是,我希望強制視頻在橫向上全屏播放(就像iPhone上的iPod應用程序一樣)。

經過四處搜尋,我發現很多人都有這個問題。

我終於可以旋轉它,但它不能在全屏幕中工作,默認爲肖像。

而且由於它不能全屏顯示,您可以在視頻中看到父視圖中的元素。

是否有一種簡單的方法來全屏旋轉此視頻,還是必須向視頻播放時向父視圖播放消息以隱藏元素?

這裏是代碼:

NSURL *url = [NSURL URLWithString:[recipeData objectForKey:@"videoPath"]]; 

    MPMoviePlayerController *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:moviePlayer]; 


     moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 
     moviePlayer.scalingMode = MPMovieScalingModeAspectFill; 
     moviePlayer.shouldAutoplay = YES; 
     moviePlayer.view.frame = [[UIScreen mainScreen] applicationFrame]; 
     moviePlayer.view.transform = CGAffineTransformMakeRotation(1.57079633); 
     moviePlayer.view.bounds = CGRectMake(0.0, 0.0, 480, 320); 

     [self.view addSubview:moviePlayer.view]; 
//commenting out the line below will rotate the video, leaving it uncommented forces it to play fullscreen in portrait 
     [moviePlayer setFullscreen:YES animated:NO]; 

回答

1

我把方法在appDelegate中創建視頻,並在視頻啓動時將其定位。這樣做訣竅,把它放在一切之上。

0

您是否嘗試過使用MPMoviePlayerViewController呢?它提供了一個全屏幾乎模態視圖控制器來處理視頻播放。我在> = 3.2版本中使用它,並使用MPMoviePlayerController的黑客版本< 3.2

+0

不幸的沒有按;噸做的伎倆要麼因爲MPMoviePlayerViewController是當前視圖的子視圖。所以你可以看到視頻上方的父視圖菜單。 [moviePlayer setFullscreen:YES animated:NO];在我的原始片段中,將視頻置於最高級別,將其鎖定爲肖像。 – 2011-01-19 21:38:38

0

對於全屏播放,您應該使用MPMoviePlayerViewController,然後在MPMoviePlayerViewController類中使用「shouldAutorotateToInterfaceOrientation」方法啓動並播放橫向格式。

看起來像這樣:

[yourInstanceOfMPMoviePlayerViewController shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight];