Adding an MPMoviePlayerController in full screen mode?

前端 未结 2 1335
萌比男神i
萌比男神i 2020-12-29 13:32

I have a UIButton in my iPhone app that, when clicked, plays a movie. The code to play the movie looks like this:

NSURL *url = [[NSBundle mainBundle] URLFor         


        
2条回答
  •  时光说笑
    2020-12-29 14:09

    Assuming that self.view is using the entire screen:

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
    [moviePlayer.view setFrame: self.view.bounds];
    [self.view addSubview: moviePlayer.view];
    [moviePlayer play];
    

    Now assuming that you basically dont want to use the current self.view but simply have it working in fullscreen (I call this; fake-fullscreen as it does not invoke the fullscreen-property);

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"Robot" withExtension:@"m4v"];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
    UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
    [moviePlayer.view setFrame:backgroundWindow.frame];
    [backgroundWindow addSubview:moviePlayer.view];
    [moviePlayer play];
    

提交回复
热议问题