【问题标题】:Playing video in Landscape and portrait横向和纵向播放视频
【发布时间】:2015-05-25 08:42:03
【问题描述】:

我的应用处于纵向模式。

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

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

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

【问题讨论】:

  • 你的 rootViewController uinavigationcontroller 或 uitabbarcontroller 是什么??
  • 问题的标题应该是重点。并在问题正文中使用一些解释。
  • 您是否只是尝试运行应用程序然后打开模拟器?还是实际设备?

标签: ios objective-c


【解决方案1】:
For you question i would like to give the below Reference

Portrait video to landscape

Allow video on landscape with only-portrait app

【讨论】:

    【解决方案2】:

    在部署信息中启用您的横向设备方向。然后,在您的 ViewController 中添加这些方法:

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

    【讨论】:

      【解决方案3】:

      尝试将画布视图作为超级视图添加到您的播放器,并将转换应用到画布视图。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多