在另一个视图中打开电影流
我的应用程序中有一个包含许多选项卡的选项卡视图,其中一个选项卡中有一个按钮,单击该按钮时,我想在视图中显示电影流。我有这样的代码:
NSString *moviePath = @"http://10.0.0.4/prog_index.m3u8";
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
[theMovie.view setFrame:CGRectMake(0, 0, (self.view.frame.size.width), (self.view.frame.size.height))];
theMovie.view.backgroundColor = [UIColor grayColor];
theMovie.view.tag = 9999;
[self.view addSubview:[theMovie view]];
[theMovie play];
视图出现,但视频没有开始。怎么了?
I have in my app a tab view with many tabs, and in one of them I have a button that when is clicked, I want to show a movie stream in a view. I have this code:
NSString *moviePath = @"http://10.0.0.4/prog_index.m3u8";
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
[theMovie.view setFrame:CGRectMake(0, 0, (self.view.frame.size.width), (self.view.frame.size.height))];
theMovie.view.backgroundColor = [UIColor grayColor];
theMovie.view.tag = 9999;
[self.view addSubview:[theMovie view]];
[theMovie play];
The view appears, but the video doesn't start. What is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在向MPMoviePlayerController
传递一个指向 m3u8 文件的 URL。那是一个播放列表。要使用MPMoviePlayerController
播放媒体,您必须将其设置为实际的视频文件。您应该解析播放列表以获取真实视频的链接,然后使用真实链接初始化MPMoviePlayerController
。检查M3U - 维基百科和
MPMoviePlayerController
参考另请检查此相关问题编辑:感谢雨果·席尔瓦,我意识到
MPMoviePlayerController
能够播放m3u8格式的直播流,由于我没有发现您的代码有任何问题,我建议您检查是否是您的流的问题。尝试使用 Apple 提供的示例之一。另请确保您的流满足 Apple 对 HTTP 流You're passing to theMPMoviePlayerController
an URL pointing to a m3u8 file. That is a playlist. To play media withMPMoviePlayerController
, you have to set it an actual video file. You should parse the playlist to get the link to the real video and then init yourMPMoviePlayerController
with the real link.Check M3U - Wikipedia and
MPMoviePlayerController
referenceAlso check this related questionEDIT: Thanks to Hugo Silva, I realized that
MPMoviePlayerController
is able to play live streams in m3u8 format, since I've not seen anything wrong in your code, I suggest you to check if it's a problem of your stream. Try using one of the samples provided by Apple. Also make sure that your stream meets Apple's requirements for HTTP Streaming