MPMoviePlayerController 问题、最佳实践

发布于 2024-09-28 18:54:06 字数 722 浏览 3 评论 0原文

我有任意数量的缩略图,点击这些缩略图时,将播放不同的视频(全屏)。我一直不清楚是否应该在视图控制器中保留一个 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 技术交流群。

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

发布评论

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

评论(1

七度光 2024-10-05 18:54:06

当您更改 MPMovieplayerController 中的视频时,您可以使用 removeFromSuperView 从超级视图中删除 mpmoviecontrollerplayer 视图,然后再次将其子视图添加到超级视图用新的 URL 初始化它。
无需每次都创建新对象。

When you are changing the video in an MPMovieplayerController,then you can remove the mpmoviecontrollerplayer view from super view using removeFromSuperView and again add it's subview to the super view initializing it with new URL.
No need to create new object every time.

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