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

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

#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】;

}

相关文章
|
1月前
|
编解码 监控 C++
C++音视频编程探秘
C++音视频编程探秘
108 1
|
9月前
|
Web App开发 编解码 安全
音视频绕不开的话题之WebRTC
闲来无事,我们今天探讨下音视频绕不开的一个话题:WebRTC。WebRTC之于音视频行业,无异于FFMpeg,可以说WebRTC的开源,让音视频行业大跨步进入发展快车道。
156 0
|
10月前
|
人工智能 算法 Linux
流媒体:浅谈传统媒体—>流媒体—>加P2P的流媒体的演变之路
从传统媒体—&gt;流媒体—&gt;含P2P流媒体:技术复杂度逐渐递增,人的体验越来越好;随着人类的生活越来越丰富需求越来越高,从而推动技术在不断的发展;
124 0
|
9月前
|
缓存 监控 算法
RTMP播放器开发填坑之道
好多开发者提到,在目前开源播放器如此泛滥的情况下,为什么还需要做自研框架的RTMP播放器,自研和开源播放器,到底好在哪些方面?以下大概聊聊我们的一点经验,感兴趣的,可以关注 github:
|
9月前
|
监控 网络协议 算法
RTSP播放器开发填坑之道
好多开发者提到,在目前开源播放器如此泛滥的情况下,为什么还需要做自研框架的RTSP播放器,自研和开源播放器,到底好在哪些方面?以下大概聊聊我们的一点经验,感兴趣的,可以关注 github:
|
Kubernetes 应用服务中间件 Go
使用Go语言开发流媒体视频网站
基于Go语言实现简单的流媒体视频网站
|
数据安全/隐私保护
关于直播平台开发中流媒体传输,重点干货分享
随着近年来直播行业的飞速发展,直播平台开发的技术日益成熟,直播系统的应用场景也越来越广泛,也离不开流媒体传输的技术支持,本文就主要介绍了当前主流的流媒体传输中推流端及播放端分别需要几步。
关于直播平台开发中流媒体传输,重点干货分享
|
编解码 缓存 算法
直播软件开发科普之流媒体介绍
直播软件开发编解码 硬编解码 通过硬件实现编解码,减轻CPU计算的负担,如GPU等 软编解码 如 H264、H265、MPEG-4等编解码算法,更消耗CPU
|
存储 视频直播
如何理解直播APP源码开发中的音视频同步
视频 直播APP源码的视频的播放过程可以简单理解为一帧一帧的画面按照时间顺序呈现出来的过程,就像在一个本子的每一页画上画,然后快速翻动的感觉。
|
编解码 测试技术
手机直播平台开发一定要懂的知识:编解码
手机直播平台开发一定要懂的知识:编解码