视频播放一

1.使用注意事项

导入框架
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>

2.使用

AVPlayerViewController *_playerVc;
 Video *video = _videos[indexPath.row];
    NSString *url = [baseUrlStr stringByAppendingPathComponent:video.url];
  
    //ios9.0以下
    if([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0){
        if (_playerVc == nil) {
            _playerVc = [[AVPlayerViewController alloc] init];
        }
        _playerVc.player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:url]];
        /*
         可以设置的值及意义如下:
         AVLayerVideoGravityResizeAspect   不进行比例缩放 以宽高中长的一边充满为基准
         AVLayerVideoGravityResizeAspectFill 不进行比例缩放 以宽高中短的一边充满为基准
         AVLayerVideoGravityResize     进行缩放充满屏幕
         */
        _playerVc.videoGravity = AVLayerVideoGravityResizeAspectFill;
        [self presentViewController:_playerVc animated:YES completion:nil];
        [_playerVc shouldAutorotate];
    }else{
//需要导入#import <MediaPlayer/MediaPlayer.h>框架
        MPMoviePlayerViewController *play = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
        [self presentViewController:play animated:YES completion:nil];
    }

  

  

原文地址:https://www.cnblogs.com/TheYouth/p/6745252.html