视频播放一

1.使用注意事项

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

2.使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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];
    }

  

  

posted @   TheYouth  阅读(271)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示