【问题标题】:Playing video in custom size screen - view in iPhone在自定义尺寸屏幕中播放视频 - 在 iPhone 中查看
【发布时间】:2010-11-28 05:15:51
【问题描述】:

假设用户点击一个按钮,视频开始播放。现在,当视频播放时,它始终处于全屏模式。

视频应以纵向模式播放(但通常视频以横向模式播放)。我该怎么做?

【问题讨论】:

  • 这是这个问题的重复:stackoverflow.com/questions/1347395/…
  • 好的。这里我的要求只是以纵向模式播放视频。查看我的新编辑问题。
  • 问题可能重复。但答案不重复。

标签: iphone uiview mpmovieplayercontroller


【解决方案1】:

只是一个更新,最新的 iPhone SDK 3.2+ 现在允许程序员以任何所需的大小和方向显示视频,提供了新的 MPMoviePlayerView,它是 MPMoviePlayerController 的一个属性,这个视图将有视频,你可以作为子视图添加到您的视图中。

【讨论】:

    【解决方案2】:
    @interface MPMoviePlayerController (extend) 
     -(void)setOrientation:(int)orientation animated:(BOOL)value; 
    @end 
    
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR]; 
    [moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO]; 
    if (moviePlayer) 
    { 
        [self.moviePlayer play]; 
    } 
    

    此解决方案将被 Apple 拒绝,因为电影播放器​​的 setOrientation 是私有 API。您需要小心,但它可能适用于越狱 iPhone。

    【讨论】:

      【解决方案3】:

      根据文档文档,我认为使用内置媒体播放器无法做到这一点

      【讨论】:

      • 我们可以创建自定义媒体播放器吗?
      • 好的。这里我的要求只是以纵向模式播放视频。查看我的新编辑问题。
      • 请尝试新的 MPMoviePlayerController ,在 iPhone SDK 3.2+ 中可用,它允许您自定义、设置所需的大小以及更改方向。
      【解决方案4】:

      试试这个。 我发现了一些新东西。

      @interface MPMoviePlayerController (extend)
      -(void)setOrientation:(int)orientation animated:(BOOL)value;
      @end
      
      moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
      [moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
      if (moviePlayer)
      {
          [self.moviePlayer play];
      }
      

      【讨论】:

        【解决方案5】:

        这就是我所做的。添加 NSNotification 以在视频预加载完成时通知您。

        - (void)playVideoUrl:(NSString *)videoUrl {
            NSURL *url = [NSURL URLWithString:videoUrl];
            MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc]   
                     initWithContentURL:url]; 
            [[NSNotificationCenter defaultCenter] addObserver:self 
        
            //MPMoviePlayerContentPreloadDidFinishNotification
            [[NSNotificationCenter defaultCenter] addObserver:self                           
                               selector:@selector(myMovieFinishedPreloading:)                                            
                                   name:MPMoviePlayerContentPreloadDidFinishNotification                                                
                                 object:theMovie]; 
        
        
            // Movie playback is asynchronous, so this method returns immediately. 
            [theMovie play]; 
             }
        

        回调选择器:

        -(void)myMovieFinishedPreloading:(NSNotification*)aNotification  {
            NSArray *windows = [[UIApplication sharedApplication] windows];
        
            UIWindow *moviePlayerWindow = nil;
            if ([windows count] > 1) 
            {
                moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
            }
        
            CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
            transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
            [moviePlayerWindow setTransform:transform];
        
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-06-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多