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

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:@""];

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

当你想同时加载多个视频时, 可以将加载 WebView 的方法复制多个, 改变下布局即可

你可能感兴趣的:(流媒体/视频播放(拉流的四种加载方式))