开发者

Play video by default in full screen

开发者 https://www.devze.com 2023-03-05 15:16 出处:网络
I am playing a video by using MPMoviePlayerController: NSString *urlStr = [[NSBundle mainBundle] pathForResource:@\"myvideo.MOV\" ofType:nil];

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 vide开发者_Python百科o should be in full screen and when I minimize it should be in above frame size.

Please help me out.


Try this.

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

精彩评论

暂无评论...
验证码 换一张
取 消