在iOS中实现HTTP Live Streaming

我想写一个小小的iOSvideo客户端,并且必须使用HTTP Live Streaming。 这些video来自支持HTTP Live Streaming的Wowza媒体服务器,所以服务器端的实现不是我的问题。 我已经观看了WWDCvideo,并阅读了关于HTTP Live Streaming的Apple文档。

但是没有任何地方可以解释如何在iOS设备上播放video。 在WWDC的演讲中,有人提到有3个组合可以显示video:

  • UIWebView的
  • 的MPMoviePlayerController
  • AVPlayerItem

哪一个是最好的?

而我怎样才能从这样的HTML页面读出videoURL,这些信息将由服务器提供?

<html> <head> <title>HTTP Live Streaming Example</title> </head> <body> <video src="http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8" height="300" width="400" > </video> </body> </html> 

(来源: Apple HTTP Live Streaming Overview )

我真的不知道从哪里开始编码…也许有人知道比烦人的“缝合stream播放器”更好的示例代码,或者可以写一个小教程…

一个简短的和点的实现。 包含的url指向一个有效的stream(截至2015年12月15日),但您可以用自己的URLreplace为.m3u8文件。

Objective-C的:

 #import <MediaPlayer/MediaPlayer.h> @interface ViewController () @property (strong, nonatomic) MPMoviePlayerController *streamPlayer; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSURL *streamURL = [NSURL URLWithString:@"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"]; _streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL]; // depending on your implementation your view may not have it's bounds set here // in that case consider calling the following 4 msgs later [self.streamPlayer.view setFrame: self.view.bounds]; self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded; [self.view addSubview: self.streamPlayer.view]; [self.streamPlayer play]; } - (void)dealloc { // if non-ARC // [_streamPlayer release]; // [super dealloc]; } @end 

迅速:

 import UIKit import MediaPlayer class ViewController: UIViewController { var streamPlayer : MPMoviePlayerController = MPMoviePlayerController(contentURL: NSURL(string:"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8")) //Let's play override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. streamPlayer.view.frame = self.view.bounds self.view.addSubview(streamPlayer.view) streamPlayer.fullscreen = true // Play the movie! streamPlayer.play() } } 

更新了两种语言的答案。 此外, MPMoviePlayerController在iOS 9中已被弃用,但您可以改用AVPlayerViewController 。 快乐的编码。

如果你指向一个UIWebView在目标m3u8 URL,它将会正常工作。