MPMoviePlayerController 问题、最佳实践
我有任意数量的缩略图,点击这些缩略图时,将播放不同的视频(全屏)。我一直不清楚是否应该在视图控制器中保留一个 MPMoviePlayerController 对象并让它根据点击的缩略图播放任何一个 url,或者每次都创建一个新的 MPMoviePlayerController。最佳实践是什么?
我还遇到了点击不同拇指会使应用程序崩溃的问题,我相信是因为 MPMoviePlayerController 在已经尝试流式传输时尝试流式传输视频。似乎没有办法取消 MPMoviePlayerController 并清除它正在执行的操作,然后开始加载新视频。
以下是我的创建方法:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];
然后要播放视频,我会这样做:
//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];
欢迎任何建议...谢谢。
I have any number of thumbnail images that, when tapped, will play a different video (fullscreen). I have never been clear on whether I should keep one MPMoviePlayerController object in my view controller and have it play whichever url according to the thumbnail that was tapped, or create a new MPMoviePlayerController each time. What is the best practice?
I am also having problems where tapping on different thumbs crashes the app, I believe because the MPMoviePlayerController tries to stream a video while it is already trying to stream. There seems to be no way to cancel a MPMoviePlayerController and clear out what it was doing, then start loading a new video.
Here's how I create it:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];
Then to play a video I do this:
//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];
Any advice is welcome... thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您更改
MPMovieplayerController
中的视频时,您可以使用removeFromSuperView
从超级视图中删除mpmoviecontrollerplayer
视图,然后再次将其子视图添加到超级视图用新的 URL 初始化它。无需每次都创建新对象。
When you are changing the video in an
MPMovieplayerController
,then you can remove thempmoviecontrollerplayer
view from super view usingremoveFromSuperView
and again add it's subview to the super view initializing it with new URL.No need to create new object every time.