程序员必知:关于流媒体视频

简介: 程序员必知:关于流媒体视频

#import "ViewController.h"

#import

#import

/

/

static const NSString PlayerItemStatusContext;

@interface ViewController ()

@property (nonatomic, strong) AVPlayer player;

@end

@implementation ViewController

- (void)viewDidLoad {

【super viewDidLoad】;

// //1. 根据网址创建AVPlayer

// self.player = 【AVPlayer playerWithURL:【NSURL URLWithString:@""】】;

//

// //2. 创建PlayerLayer

// AVPlayerLayer playerLayer = 【AVPlayerLayer playerLayerWithPlayer:self.player】;

//

// //3. 设置大小

// playerLayer.frame = self.view.bounds;

//

// //4. 添加到layer中

// 【self.view.layer addSublayer:playerLayer】;

//

// //5. 播放

// 【self.player play】;

//

}

- (IBAction)playLocalVideoClick:(id)sender {

NSURL assetURL = 【【NSBundle mainBundle】 URLForResource:@"02开发环境.mp4" withExtension:nil】;

//

// AVAsset asset = 【AVAsset assetWithURL:assetURL】;

//

// AVPlayerItem playerItem = 【AVPlayerItem playerItemWithAsset:asset】;

//

// 【playerItem addObserver:self forKeyPath:@"status" options:0 context:PlayerItemStatusContext】;

//

// self.player = 【AVPlayer playerWithPlayerItem:playerItem】;

self.player = 【AVPlayer playerWithURL:assetURL】;

AVPlayerLayer playerLayer = 【AVPlayerLayer playerLayerWithPlayer:self.player】;

playerLayer.frame = self.view.bounds;

【self.view.layer addSublayer:playerLayer】;

【self.player play】;

}

- (IBAction)playRomoteVideoClick:(id)sender {

//1. AVPlayerItem会创建媒体资源动态视角的数据模型(比如当前播放时间, 实现时间跳转等), 并保存AVPlayer在播放资源时的呈现状态

AVPlayerItem playerItem = 【AVPlayerItem playerItemWithURL:【NSURL URLWithString:@""】】;

【playerItem addObserver:self forKeyPath:@"status" options:0 context:PlayerItemStatusContext】;

self.player = 【AVPlayer playerWithPlayerItem:playerItem】;

AVPlayerLayer playerLayer = 【AVPlayerLayer playerLayerWithPlayer:self.player】;

playerLayer.frame = self.view.bounds;

【self.view.layer addSublayer:playerLayer】;

}

- (void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary<NSString ,id

{

if (context == PlayerItemStatusContext) {

AVPlayerItem playerItem = (AVPlayerItem )object;

if (playerItem.status == AVPlayerItemStatusReadyToPlay) {

【self.player play】;

}

}

}

- (IBAction)mpVCPlayRomoteClick:(id)sender {

MPMoviePlayerViewController mpvc = 【【MPMoviePlayerViewController alloc】 initWithContentURL:【NSURL URLWithString:@""】】;

【self presentModalViewController:mpvc animated:YES】;

}//代码效果参考:http://www.ezhiqi.com/zx/art_3244.html

- (void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event

{

// 【self.player play】;

}//代码效果参考:http://www.ezhiqi.com/bx/art_963.html

这是一个小demo的实现

#import "ViewController.h"

#import

#import

@interface ViewController ()

@property(nonatomic,strong)AVPlayer player;//播放对象

@property(nonatomic,strong)MPMoviePlayerController *mc;

@end

@implementation ViewController

- (void)viewDidLoad {

【super viewDidLoad】;

// Do any additional setup after loading the view, typically from a nib.

}//代码效果参考:http://www.ezhiqi.com/zx/art_2750.html

/

/

- (IBAction)clik:(id)sender {

//1mpc:

// self.mc=【【MPMoviePlayerController alloc】initWithContentURL:【NSURL URLWithString:@""】】;

// self.mc.view.frame=CGRectMake(0, 200, 375, 200);

// 【self.view addSubview:self.mc.view】;

// 【self.mc play】;

//2mpvc

// MPMoviePlayerViewController mpv=【【MPMoviePlayerViewController alloc】initWithContentURL:【NSURL URLWithString:@""】】;

// 【self presentViewController:mpv animated:YES completion:nil】;

//3Aplayer

//根据网址创建

self.player=【AVPlayer playerWithURL:【NSURL URLWithString:@""】】;

AVPlayerLayer *player=【AVPlayerLayer playerLayerWithPlayer:self.player】;

player.frame=self.view.bounds;

【self.view.layer addSublayer:player】;

//播放

【self.player play】;

}

相关文章
|
8月前
|
Java Spring
Spring框架的学习与应用
总的来说,Spring框架是Java开发中的一把强大的工具。通过理解其核心概念,通过实践来学习和掌握,你可以充分利用Spring框架的强大功能,提高你的开发效率和代码质量。
201 20
|
安全 网络安全 云计算
全国公安机关互联网站安全服务平台(公安局、公安局备案、接入方式)
全国公安机关互联网站安全服务平台(公安局、公安局备案、接入方式)【云·速成美站】
|
网络协议 开发者
TCP连接的四次挥手过程及其必要性
在网络通信中,TCP(传输控制协议)以其可靠性和有序性著称。TCP连接的建立和终止都需要特定的握手过程。本文将详细描述TCP连接的四次挥手(四次挥手)过程,并探讨为什么需要四次挥手来终止一个TCP连接。
484 8
|
XML JSON Java
springboot文件上传,单文件上传和多文件上传,以及数据遍历和回显
本文介绍了在Spring Boot中如何实现文件上传,包括单文件和多文件上传的实现,文件上传的表单页面创建,接收上传文件的Controller层代码编写,以及上传成功后如何在页面上遍历并显示上传的文件。同时,还涉及了`MultipartFile`类的使用和`@RequestPart`注解,以及在`application.properties`中配置文件上传的相关参数。
springboot文件上传,单文件上传和多文件上传,以及数据遍历和回显
|
数据采集 机器学习/深度学习 数据可视化
R实战| PCA、tSNE、UMAP三种降维方法在R中的实现
R实战| PCA、tSNE、UMAP三种降维方法在R中的实现
749 0
keep-alive 组件有哪些常用的属性和配置选项
keep-alive 组件有哪些常用的属性和配置选项
|
前端开发 JavaScript Java
解决springboot+vue+mybatis中,将后台数据分页显示在前台,并且根据页码自动跳转对应页码信息
该博客文章讲述了如何在Spring Boot + Vue + MyBatis的项目中实现后台数据的分页查询,并在前端进行显示和页码跳转,包括后端的分页查询实现、前端与后端的交互以及使用Element UI进行分页展示的方法。
|
NoSQL Java 数据库
重复点击提交、产生多笔数据、保持数据只操作一次---->接口幂等性校验
重复点击提交、产生多笔数据、保持数据只操作一次---->接口幂等性校验
320 0
|
缓存 Linux
修改CentOS默认yum源为国内镜像
修改CentOS默认yum源为国内镜像
2538 0
|
存储 Web App开发 缓存
跑ChatGPT体量模型,从此只需一块GPU:加速百倍的方法来了
跑ChatGPT体量模型,从此只需一块GPU:加速百倍的方法来了
390 0
跑ChatGPT体量模型,从此只需一块GPU:加速百倍的方法来了

热门文章

最新文章