Set ContentURL of MPMoviePlayerController twice

馋奶兔 提交于 2019-12-05 19:08:27

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!