假设用户点击按钮并且视频开始播放。现在,当视频播放时,它始终处于全屏模式。

视频应以纵向模式播放(但通常视频以横向模式播放)。我怎样才能做到这一点?

有帮助吗?

解决方案

@interface MPMoviePlayerController (extend) 
 -(void)setOrientation:(int)orientation animated:(BOOL)value; 
@end 

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR]; 
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO]; 
if (moviePlayer) 
{ 
    [self.moviePlayer play]; 
} 

该解决方案将被Apple拒绝,因为电影播放器​​的setOrientation是私有API。你需要小心,但它可能适用于越狱的 iPhone。

其他提示

只是一个更新,最新的iPhone SDK 3.2+现在将允许程序员以任何所需的大小和方向显示视频,提供新的MPMoviePlayerView,这是MPMoviePlayerController的属性,这个视图将有视频,你可以添加为您的视图的子视图。

从文档化的文档中我不认为使用内置媒体播放器可以实现这一点

试一试。 我找到了新的东西。

@interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
@end

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
    [self.moviePlayer play];
}

这就是我的所作所为。添加NSNotification以在预加载视频完成时通知您。

- (void)playVideoUrl:(NSString *)videoUrl {
    NSURL *url = [NSURL URLWithString:videoUrl];
    MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc]   
             initWithContentURL:url]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 

    //MPMoviePlayerContentPreloadDidFinishNotification
    [[NSNotificationCenter defaultCenter] addObserver:self                           
                       selector:@selector(myMovieFinishedPreloading:)                                            
                           name:MPMoviePlayerContentPreloadDidFinishNotification                                                
                         object:theMovie]; 


    // Movie playback is asynchronous, so this method returns immediately. 
    [theMovie play]; 
     }

回调选择器:

-(void)myMovieFinishedPreloading:(NSNotification*)aNotification  {
    NSArray *windows = [[UIApplication sharedApplication] windows];

    UIWindow *moviePlayerWindow = nil;
    if ([windows count] > 1) 
    {
        moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
    }

    CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
    transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
    [moviePlayerWindow setTransform:transform];

 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top