IOS在线的播放视频
2015-08-02 11:46
411 查看
第一种:
//UIWebView 加在网络视频 在线播放 有声音
UIWebView *myWeb = [[UIWebView alloc] initWithFrame:self.view.bounds];
NSURL *url = [NSURLURLWithString:@"
http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]; http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8//这里也可以是 mp4
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWeb setDelegate:self];
[myWeb loadRequest:request];
[self.view addSubview:myWeb];
第二种:
//AVPlayerLayer 播放在线视频 无声音
NSURL *sourceMovieURL = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURLoptions: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];
第三种:
//MPMoviePlayerController 播放在线视频 无声音
NSURL *videoURL = [NSURLURLWithString:@"https://s3.amazonaws.com/adplayer/colgate.mp4"];
MPMoviePlayerViewcontroller *moviePlayerController
= [[MPMoviePlayerViewcontroller alloc] initWithContentURL:videoURL];
moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayerController.moviePlayer.shouldAutoplay = YES;
//moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayerController.moviePlayer prepareToPlay];
[moviePlayerController.moviePlayer play];
[[NSnotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishnotification
object: moviePlayerController];
[self presentMoviePlayerViewcontrollerAnimated:moviePlayerController];
参考:/article/9559368.html
//UIWebView 加在网络视频 在线播放 有声音
UIWebView *myWeb = [[UIWebView alloc] initWithFrame:self.view.bounds];
NSURL *url = [NSURLURLWithString:@"
http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"]; http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8//这里也可以是 mp4
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWeb setDelegate:self];
[myWeb loadRequest:request];
[self.view addSubview:myWeb];
第二种:
//AVPlayerLayer 播放在线视频 无声音
NSURL *sourceMovieURL = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVAsset *movieAsset = [AVURLAsset URLAssetWithURL:sourceMovieURLoptions: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];
第三种:
//MPMoviePlayerController 播放在线视频 无声音
NSURL *videoURL = [NSURLURLWithString:@"https://s3.amazonaws.com/adplayer/colgate.mp4"];
MPMoviePlayerViewcontroller *moviePlayerController
= [[MPMoviePlayerViewcontroller alloc] initWithContentURL:videoURL];
moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
moviePlayerController.moviePlayer.shouldAutoplay = YES;
//moviePlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
[moviePlayerController.moviePlayer prepareToPlay];
[moviePlayerController.moviePlayer play];
[[NSnotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishnotification
object: moviePlayerController];
[self presentMoviePlayerViewcontrollerAnimated:moviePlayerController];
参考:/article/9559368.html
相关文章推荐
- Cisco IOS版本命名规则
- cs193p斯坦福视频学习总结——iOS基础知识
- iOS Quartz2D - 条纹背景
- iOS Quartz2D - 屏幕截图
- iOS Quartz2D - 给图片加水印
- iOS Quartz2D - 裁剪图片为带边框的圆形图片
- IOS Block详解
- iOS Quartz2D - 矩阵操作
- ios-状态栏的改变
- Foundation框架-学习笔记<一>
- iOS Quartz2D - 画文字 和 图片
- [iOS]用instancetype代替id作返回类型有什么好处?
- ios中字符串(NSString)用法总结(持续更新)
- iOS键盘下落的方式
- 【转】iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- iOS设计模式 - 抽象工厂
- iOS 学习资料整理
- iOS多线程——GCD篇
- Cocoapods Podfile配置
- iOS开发之沙盒机制(SandBox)