iOS 关于流媒体 的初级认识与使用
2024-09-24 05:43:41
1.流媒体指在Internet/Intranet中使用流式传输技术的连续时基媒体,如:音频、视频或多媒体文件。流式媒体在播放前并不下载整个文件,只将开始部分内容存入内存,流式媒体的数据流随时传送随时播放,只是在开始时有一些延迟。流媒体实现的关键技术就是流式传输。
2.这里的流媒体地址是指服务端那边已经调好格式的可以在ios上播放的视频流。
举例:http://www.jxvdy.com/file/upload/201309/18/18-10-03-19-3.mp4
3.iOS的影片播放 MediaPlayer 和 AVPlayer(framework)
在iOS开发商,如果要遇到播放影片,如开机动画,我們很習慣地會使用MediaPlayer來播放影片,因為很方便使用,所以就一直使用下去。但是隨著客戶的要求越來越嚴苛,尤其是過場動畫或互動效果上的表現。所以如果在一些動畫中還挾帶影片一起運算,那勢必機器會跑不動。所以在iOS 4之後,我們可以使用AVPlayer這個類別來進行更細微的操作。
備註:
- MediaPlayer的影片是放在UIView 裡面,而AVPlayer是放在AVPlayerLayer裡面,AVPlayerLayer是CALayer 的子類別。
- 使用MediaPlayer前,要記得加入MediaPlayer.framework及#import <MediaPlayer/MediaPlayer.h>
- 使用AVPlayer前,要記得加入AVFoundation.frameworkk及#import <AVFoundation/AVFoundation.h>
請參考以下的範例:
使用MediaPlayer來播放影片
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"backspace" ofType:@"mov"];
NSURL *sourceMovieURL = [NSURL fileURLWithPath:filePath]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:sourceMovieURL];
moviePlayer.view.frame=CGRectMake(, , , );
moviePlayer.controlStyle=MPMovieControlStyleNone; // Play the movie!
[self.view addSubview:moviePlayer.view];
使用AVPlayer來播放影片:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"backspace" ofType:@"mov"];
NSURL *sourceMovieURL = [NSURL fileURLWithPath:filePath]; AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURL options:nil];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:movieAsset];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.view.layer.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspect; [self.view.layer addSublayer:playerLayer];
[player play];
最新文章
- SQL优化案例—— RowNumber分页
- Jenkins学习四:Jenkins 邮件配置
- Linux命令--删除软连接
- Nginx的第一个模块-HelloWorld
- select 触发事件
- cocoapods 更新
- 2015暑假多校联合---CRB and His Birthday(01背包)
- 时序列数据库武斗大会之TSDB名录 Part 2
- zookeeper 数据存储特点
- css3换行的三方式的对比(整理)
- JSP EL隐含对象
- 如何使用Python读取大文件
- 移动端click事件出现300ms延迟
- @staticmethod和@classmethod
- Python设计模式 - UML - 交互概述图(Interaction Overview Diagram)
- day 2 - 逻辑运算
- Ubuntu Eclipse C++运行问题:launch failed.Binary not found
- 田螺便利店—PyCharm安装第三方库
- MySQL聚合函数与数据分组
- BZOJ 3091: 城市旅行 lct 期望 splay