首页 文章

在风景和肖像中播放视频

提问于
浏览
0

我的应用程序处于纵向模式 .

当视频播放器进入全屏模式时,我想以横向和纵向播放该视频 .

moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];

[moviePlayer setScalingMode:MPMovieScalingModeFill];

moviePlayer.view.frame = CGRectMake(0, 0, self.videoPlayerView.frame.size.width, self.videoPlayerView.frame.size.height);
[self.videoPlayerView addSubview:moviePlayer.view];

我正在一个按钮上播放它 .

3 回答

  • 0
    For you question i would like to give the below Reference
    

    Portrait video to landscape

    Allow video on landscape with only-portrait app

  • 0

    在部署信息中启用横向设备方向 . 然后,在ViewController中添加以下方法:

    - (BOOL) shouldAutorotate {
        return NO;
    }
    
    - (NSUInteger) supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    - (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
        return UIInterfaceOrientationPortrait;
    }
    
  • 0

    尝试将画布视图作为superview添加到播放器并将转换应用于画布视图 .

    - (void)initialize{    
        self.canvas = [[UIView alloc] initWithFrame: self.view.bounds];
        [self.view addSubview:self.canvas];
    
        // init moviePlayer
        moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
        ...
        [self.canvas addSubview: moviePlayer.view];
    
        // Add observers
        ...
        [[NSNotificationCenter defaultCenter] addObserver: self
                         selector: @selector(deviceOrientationDidChange)
                             name: UIDeviceOrientationDidChangeNotification
                           object: nil];
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    }
    
    - (void)deviceOrientationDidChange{
        // Apply rotation only in full screen mode
        if (self.isFullScreen) {
            UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;
    
            [UIView animateWithDuration: 0.3 
                             animations: ^{
                 CGAffineTransform transform = CGAffineTransformMakeRotation(0);
                 switch (orientation) {
                     case UIDeviceOrientationLandscapeLeft:
                         transform = CGAffineTransformMakeRotation(M_PI_2);
                     break;
                     case UIDeviceOrientationLandscapeRight:
                         transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);
                     break;
                     default:
                     break;
                };
    
                self.canvas.transform = transform;
                self.canvas.frame = self.canvas.superview.bounds;
            }];
        }
    }
    

相关问题