【问题标题】:Play video by default in full screen默认全屏播放视频
【发布时间】:2011-05-12 11:35:07
【问题描述】:

我正在使用 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];

但要求是默认情况下视频应该是全屏的,当我最小化时它应该是高于帧大小。

请帮帮我。

【问题讨论】:

    标签: iphone objective-c ipad


    【解决方案1】:

    试试这个。

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

    【讨论】:

    • degreeToRadian 是什么?
    • 嗨 Archana,对不起,我的错误,我已经更新了我的 Ans。你可以看到 whats degreeToRadian。
    • 好的,非常感谢,它成功了!!!你能告诉我当我们双击视频退出全屏时调用了哪个函数,因为我想在那里放一些代码。
    • 好的,但是请告诉我当我们双击视频退出全屏时调用了哪个函数,因为我想在那里放一些代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    相关资源
    最近更新 更多