gpt4 book ai didi

iphone - MPMoviePlayerController 和 HTTP 直播

转载 作者:行者123 更新时间:2023-12-03 18:28:21 25 4
gpt4 key购买 nike

每一个。我试图弄清楚如何使用 MPMoviePlayerController 播放实时流。为了进行测试,我使用苹果测试流示例 http://devimages.apple.com/iphone/samples/bipbopall.html 。它在 UIWebView 中完美工作,但我无法使其与 MPMoviePlayerController 一起工作。这是我的一段代码:

NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbopall.html"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];

[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];

[self.view addSubview:[mp view]];

[mp prepareToPlay];
[mp play];

实际上 Controller 收到 MPMoviePlayerPlaybackDidFinishNotification 时没有播放任何内容。哪里有问题?

最佳答案

您的问题可能出在 URL 上。 MPMoviePlayerController 想要直接指向您要播放的文件的 URL。您提供的 HTML 页面的 URL 是电影播放器​​无法理解的。这就是它在 UIWebView 中工作的原因,因为网络浏览器可以理解 HTML。如果您想了解有关问题所在的更多信息,可以执行以下操作来检查错误(引用自 Apple 文档):

To check for errors in URL loading, register for the MPMoviePlayerContentPreloadDidFinishNotification or MPMoviePlayerPlaybackDidFinishNotification notifications. On error, these notifications contain an NSError object available using the @"error" key in the notification’s userInfo dictionary.

它看起来像:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSError *error = [[notification userInfo] objectForKey:@"error"];
if (error) {
NSLog(@"Did finish with error: %@", error);
}
}

如果您想尝试播放该示例,您可以尝试直接访问流的 URL,即: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

关于iphone - MPMoviePlayerController 和 HTTP 直播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4302383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com