MPMoviePlayerController 和 HTTP 直播

发布于 2024-10-04 12:52:38 字数 1068 浏览 0 评论 0原文

每个人。我试图弄清楚如何使用 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];

实际上控制器收到 MPMoviePlayerPlaybackDidFinishNotification 而不播放任何内容。问题出在哪里?

every one. I'm trying to figure out how to play live stream using MPMoviePlayerController. For testing i'm using Apples test stream sample http://devimages.apple.com/iphone/samples/bipbopall.html.
It's perfectly working in UIWebView, but i can't make it work with MPMoviePlayerController. There is my piece of code:

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];

Actually the controller recieves MPMoviePlayerPlaybackDidFinishNotification without playing anything. Where is the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情话已封尘 2024-10-11 12:52:38

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

要检查 URL 加载中的错误,
注册为
MPMoviePlayerContentPreloadDidFinishNotification
或者
MPMoviePlayerPlaybackDidFinishNotification
通知。出错时,这些
通知包含 NSError
使用@“error”可用的对象
输入通知的 userInfo
字典。

它看起来像:

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

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

Your problem is probably with the URL. MPMoviePlayerController wants the URL directly to the file you want to play. You are providing the URL for an HTML page which the movie player doesn't understand. That is why it does work in UIWebView since a web browser understands HTML. If you want more information about what's wrong you can check the error doing the following, quoted from Apple's documentation:

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.

It would look something like:

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

If you want to try and play that sample you can try and access the URL for the stream directly, which would be: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

鹿童谣 2024-10-11 12:52:38

您应该使用直接链接来播放列表文件: http://devimages.apple.com /iphone/samples/bipbop/bipbopall.m3u8

NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];

You should use direct link to play list file: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
寄意 2024-10-11 12:52:38

在您的 NSNotification 中尝试使用 object:mp 而不是 object:nil

Try object:mp instead of object:nil in your NSNotification

原来是傀儡 2024-10-11 12:52:38

@Andrew:

这是 HTTP Live Streaming 的 Apple 文档,包括示例代码 http://developer.apple.com/library/ios/search/index.php?Search=HTTP+Live+Streaming+Overview

粪。

@Andrew:

Here is Apple documentation of HTTP Live Streaming including sample code http://developer.apple.com/library/ios/search/index.php?Search=HTTP+Live+Streaming+Overview

Dung.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文