如何旋转MPMoviePlayerController

时间:2010-06-10 23:14:13

标签: iphone ipad orientation mpmovieplayercontroller

我正在构建一个iPhone应用程序,可以根据需要从Web服务播放视频。

视频在MPMoviePlayerController中播放,iPhone设备上的一切正常。

然而,当一个人在iPad上加载iPhone应用程序时,视频会播放人像模式(顶部和底部带有信箱),而不是像在iPhone上那样使用左侧风景。

首先,视频根本没有出现,但我通过将MPMoviePlayerControllers视图添加到创建它的视图作为子视图来修复此问题,然后将其设置为全屏播放。

-

编辑原文:

我现在可以在所有轮换中在iPad上播放。有没有办法阻止它旋转,只是让它玩LandscapeLeft?

谢谢, DWAINE

3 个答案:

答案 0 :(得分:5)

iPad应用程序应支持所有四种界面方向。

编辑:我还没有设法找到官方文档来引用。可能只是iPad应用程序应该能够在所有方向上启动,但是如果它“合情合理”的话,你可以强制使用某些部分。 Apple是否拒绝您的应用是另一个问题,但我认为他们不太可能拒绝以横向播放视频的视频应用。

经过一些实验,以下似乎有效:

@interface MyMovieViewController : MPMoviePlayerViewController
@end

@implementation MyMovieViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

@end

然后只是实例化MyMovieViewController而不是MPMoviePlayerViewController。

编辑2: MPMoviePlayerViewController与MPMoviePlayerController不同;你用它来获得2.0-3.1 MPMoviePlayerController的行为。您需要将视图控制器添加到VC层次结构中,但它非常简单(并且比使用视图转换更容易):

MPMoviePlayerViewController * vc = [[MyMovieViewController alloc] initWithContentURL:aUrl];
[self presentMoviePlayerViewControllerAnimated:vc];
[vc.moviePlayer play];

答案 1 :(得分:2)

我发现这种方式只有用,但是时间设置所需的帧 -

theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL]; 
// Rotate the view for landscape playback   
[[theMovie view] setBounds:CGRectMake(-230, 155, 480, 350)];
[[theMovie view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)]; 

答案 2 :(得分:1)

在这里也可以修复横向iPad问题中的肖像问题(请参阅链接),如果不同的话,有兴趣知道你做了什么修复它。

link to thread