设置 MPMoviePlayerController 的 ContentURL 两次

发布于 2024-10-24 20:22:12 字数 865 浏览 1 评论 0原文

我在我的 loadView 方法中创建了一个嵌入的 MPMoviePlayerController:

self.moviePlayerController = [[[MPMoviePlayerController alloc] init] autorelease];

// add to view, setup moviePlayerController's view frame, etc

然后我可以加载用户选择的电影:

NSURL *fileUrl = ...
self.moviePlayerController.contentURL = fileUrl;

一切都很好。

但是,如果我再次设置 contentURL:

NSURL *fileUrl2 = ... self.movi​​ePlayerController.contentURL = fileUrl2;

即使 fileUrl2 == fileUrl1,这也不起作用。

当我更改 contentURL 时,我得到以下playbackState 和 loadState:

在第一次 setContentURL 之后:

loadState == 可播放 |通关OK

playbackState == 正在播放

在我的第二次setContentURL之后:

playbackState == 已停止

负载状态==未知

我当然可以为每部电影创建一个新的 MPMoviePlayerController,但我想确保这个问题并不意味着更大的问题。

谢谢!

I create an embedded MPMoviePlayerController thusly inside my loadView method:

self.moviePlayerController = [[[MPMoviePlayerController alloc] init] autorelease];

// add to view, setup moviePlayerController's view frame, etc

And I can later load a movie the user chooses thusly:

NSURL *fileUrl = ...
self.moviePlayerController.contentURL = fileUrl;

and everything works great.

However, if I set the contentURL again:

NSURL *fileUrl2 = ...
self.moviePlayerController.contentURL = fileUrl2;

This does not work, even if fileUrl2 == fileUrl1.

When I change the contentURL, I get the following playbackState and loadState:

After first setContentURL:

loadState == playable | playthroughOK

playbackState == playing

After my second setContentURL:

playbackState == stopped

loadState == unknown

I can of course create a new MPMoviePlayerController for every movie, but I want to make sure this issue isn't indicative of a larger problem.

Thanks!

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

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

发布评论

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

评论(2

伪装你 2024-10-31 20:22:12

在我的初始版本中,我只允许通过嵌入式控件播放电影。如果我在设置 contentURL 后强制电影立即开始播放,则一切正常:

self.moviePlayerController.contentURL = fileUrl;
[self.moviePlayerController play];

但是,这不是我想要的行为。我发现当

-[MPMoviePlayerController play]

被调用时,

-[MPMoviePlayerController prepareToPlay]

会自动被调用。显然,必须调用prepareToPlay 才能显示嵌入的控件和电影的初始帧。它似乎是在第一次调用 setContentURL 时自动调用的。

因此,我只是将 setContentURL 调用更改为以下内容,一切正常。

self.moviePlayerController.contentURL = fileUrl;
[self.moviePlayerController prepareToPlay];

In my initial version, I was only allowing movies to be played via the embedded controls. If I forced the movie to start playing immediately after setting the contentURL, everything worked fine:

self.moviePlayerController.contentURL = fileUrl;
[self.moviePlayerController play];

However, this is not the behavior I wanted. I discovered that when

-[MPMoviePlayerController play]

is called,

-[MPMoviePlayerController prepareToPlay]

is called automatically. Apparently, prepareToPlay must be called in order for the embedded controls and initial frame of the movie to show. It seems to be called automatically the first time setContentURL is called.

So, I just changed my setContentURL call to the following, and everything worked.

self.moviePlayerController.contentURL = fileUrl;
[self.moviePlayerController prepareToPlay];
一杯敬自由 2024-10-31 20:22:12

contentURL 属性的文档说明如下:

如果您在电影播放时设置此属性,该电影将暂停并开始加载新电影。新电影从头开始播放。

所以你所经历的并不是预期的行为。您可能需要使用 errorLog 属性检索并检查 MPMoviePlayerController 的错误日志。

The documentation for the contentURL property states the following:

If you set this property while a movie is playing, that movie pauses and the new movie begins loading. The new movie starts playing at the beginning.

So what you're experiencing isn't the expected behaviour. You may want to retrieve and check the error log for the MPMoviePlayerController using its errorLog property.

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