流媒体/视频播放(拉流的四种加载方式)

1. AVPlayer

AVPlayer *avplayer = [AVPlayer playerWithURL:[NSURL URLWithString:@""]];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:avplayer];
layer.frame = self.view.bounds;
[self.view.layer addSublayer:layer];
[avplayer play];

2.MPMoviePlayerController

这个已经被废弃了
MPMoviePlayerController *mpc = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@""]]; // init
mpc.view.frame = CGRectMake(0, 260, 375, 260); // frame
[self.view addSubview: mpc.view]; // 添加view
[mpc play]; // 播放

3.MPPlayerViewController

也已经被废弃
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:@""]];
[self presentMoviePlayerViewControllerAnimated:mpvc];

4.UIWebView

NSMutableString *html = [[NSMutableString alloc]init];
[html appendString:@"<html><body style='margin:0'><iframe src='"];
[html appendString:@"url"];
[html appendString:@"' width='320' height='200' frameborder='0'></iframe></body></html>"];

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 375, 260)];
[self.view addSubview:webView];
[webView loadHTMLString:html baseURL:nil];

当你想同时加载多个视频时, 可以将加载 WebView 的方法复制多个, 改变下布局即可
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容