设置 MPMoviePlayerController 的 ContentURL 两次
我在我的 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.moviePlayerController.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我的初始版本中,我只允许通过嵌入式控件播放电影。如果我在设置 contentURL 后强制电影立即开始播放,则一切正常:
但是,这不是我想要的行为。我发现当
被调用时,
会自动被调用。显然,必须调用prepareToPlay 才能显示嵌入的控件和电影的初始帧。它似乎是在第一次调用 setContentURL 时自动调用的。
因此,我只是将 setContentURL 调用更改为以下内容,一切正常。
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:
However, this is not the behavior I wanted. I discovered that when
is called,
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.
contentURL
属性的文档说明如下:所以你所经历的并不是预期的行为。您可能需要使用
errorLog
属性检索并检查MPMoviePlayerController
的错误日志。The documentation for the
contentURL
property states the following:So what you're experiencing isn't the expected behaviour. You may want to retrieve and check the error log for the
MPMoviePlayerController
using itserrorLog
property.