在自定义大小的屏幕上播放视频 - 在iPhone中查看

时间:2009-09-14 17:34:43

标签: iphone uiview mpmovieplayercontroller

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

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

5 个答案:

答案 0 :(得分:6)

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

答案 1 :(得分:3)

@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。你需要小心,但它可能适用于Jailbroke iPhone。

答案 2 :(得分:1)

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

答案 3 :(得分:1)

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

@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];
}

答案 4 :(得分:1)

这就是我的所作所为。添加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];

 }