ios:播放在线的网络视频

播放在线的网络视频

第一种:
//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];

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值