默认情况下全屏播放视频 [英] Play video by default in full screen

查看:107
本文介绍了默认情况下全屏播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MPMoviePlayerController播放视频:

I am playing a video by using MPMoviePlayerController:

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"myvideo.MOV" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0,0, 1024, 675);  
[moviePlayer play];

但要求是默认情况下视频应全屏显示,当我最小化时,应该在上面帧大小。

But requirement is that by default video should be in full screen and when I minimize it should be in above frame size.

请帮帮我。

推荐答案

试试这个。

#define degreesToRadian(x) (M_PI * (x) / 180.0)

-(void)playMovieAtURL:(NSURL*)movieURL
{
    if ([NSClassFromString(@"MPMoviePlayerController") instancesRespondToSelector:@selector(view)])
    {

 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200

        // running iOS 3.2 or better
        mViewPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
        mViewPlayer.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        CGRect newFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        mViewPlayer.view.frame = newFrame;

        CGAffineTransform landscapeTransform;
        landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
        landscapeTransform = CGAffineTransformTranslate(landscapeTransform, 80, 80);

        [mViewPlayer.view setTransform: landscapeTransform];

        [self.view addSubview:mViewPlayer.view];

        [mViewPlayer.moviePlayer play];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieDidExitFullscreen:)
                                                                                  name:MPMoviePlayerPlaybackDidFinishNotification
                                                                                  object:[mViewPlayer moviePlayer]];
#endif
    }
    else 
    {
        MPMoviePlayerController *mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

        mMPPlayer.scalingMode=MPMovieScalingModeFill;
        mMPPlayer.backgroundColor=[UIColor blackColor];

        [mMPPlayer play];

        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePlayerDidFinish:)
                                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                                    object:mMPPlayer];
    }
}

/*---------------------------------------------------------------------------
 * 
 *--------------------------------------------------------------------------*/

- (void) movieDidExitFullscreen:(NSNotification*)notification 
{    
    //[[UIApplication sharedApplication] setStatusBarHidden:YES];

    /*/ Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [self dismissModalViewControllerAnimated:YES];*/

    [[NSNotificationCenter defaultCenter] removeObserver: self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object: [notification object]];

    MPMoviePlayerController *theMovie1 = [notification object];

    [theMovie1.view removeFromSuperview];
    [theMovie1 release];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification 
{    
    //[[UIApplication sharedApplication] setStatusBarHidden:YES];

    /*/ Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:nil];

    [self dismissModalViewControllerAnimated:YES];*/

    [[NSNotificationCenter defaultCenter] removeObserver: self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object: [notification object]];

    MPMoviePlayerController *theMovie1 = [notification object];

    [theMovie1.view removeFromSuperview];
    [theMovie1 release];
}

这篇关于默认情况下全屏播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆