【问题标题】:How to play video without the full screen mode?如何在没有全屏模式的情况下播放视频?
【发布时间】:2015-07-27 04:18:57
【问题描述】:

有没有办法像使用图像和图像视图一样将视频添加到视图中?我不想要 YouTube 应用中的全屏模式。

【问题讨论】:

    标签: ios xcode video


    【解决方案1】:

    您可以使用 AVFoundation 框架中的 AVPlayer AVPlayer Demo

    【讨论】:

      【解决方案2】:

      试试这个代码。

      1.导入媒体播放器框架-#import

      2.声明实例变量 MPMoviePlayerController *player;

          -(void)viewDidLoad
          {
            //you can try other api to get movie file path in ios 8
              NSString *url = [[NSBundle mainBundle]
                               pathForResource:@"Trailer"
                               ofType:@"m4v"];
      
              player = [[MPMoviePlayerController alloc]
                        initWithContentURL:[NSURL fileURLWithPath:url]];
      
              [[NSNotificationCenter defaultCenter]
               addObserver:self
               selector:@selector(movieFinishedCallback:)
               name:MPMoviePlayerPlaybackDidFinishNotification
               object:player];
      
              //—set the size of the movie view and then add it to the View window—
              player.view.frame = CGRectMake(10, 10, 300, 300);    
              [self.view addSubview:player.view];
      
              //—play movie—
              [player play];
      
              [super viewDidLoad];
              // Do any additional setup after loading the view, typically from a nib.
          }
      
          //—called when the movie is done playing—
          - (void) movieFinishedCallback:(NSNotification*) aNotification {
              MPMoviePlayerController *moviePlayer = [aNotification object];
              [[NSNotificationCenter defaultCenter]
               removeObserver:self
               name:MPMoviePlayerPlaybackDidFinishNotification
               object:moviePlayer];   
              [moviePlayer.view removeFromSuperview];
      
          }
      
      //-(NSString *)path
      //{
      //    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, //NSUserDomainMask, YES);
      //    NSString *documentDir=[paths objectAtIndex:0];
      //    return [documentDir stringByAppendingPathComponent:@"Trailer.m4v"];
      //}
      

      【讨论】:

        猜你喜欢
        • 2011-10-27
        • 2013-01-27
        • 1970-01-01
        • 1970-01-01
        • 2018-05-05
        • 1970-01-01
        • 2013-03-07
        • 2014-01-08
        • 1970-01-01
        相关资源
        最近更新 更多