按顺序播放多媒体内容

发布于 2024-09-14 13:13:42 字数 452 浏览 6 评论 0原文

您好,我有一个 NSArray,其中包含许多我喜欢称之为的“多媒体动作”,这些对象封装了一些多媒体内容,例如电影和照片。我想按顺序“播放”它们,等待每个人完成后再打电话给另一个人。

在调用下一个操作之前管理每个操作的持续时间的最佳方法是什么?(对于照片,想象一下 UIAlertView 在几秒延迟后关闭,对于电影,想象一下 MPMoviePlayerController)

我是已经调用了使用 NSOperation 扫描数组的方法。

重要: MPMovieController 似乎无法播放(甚至没有出现界面),无论是在 NSOperation 内部调用。还有其他人遇到过这个问题吗?

更新使用performSelectorOnMainThread:使MPMoviePlayer按预期工作

Hi I have an NSArray containing many 'multimedia action' as I like to call them, objects that encapsulate some multimedia content like movies and photos. I'd like to 'play' them in sequence waiting each one finished before calling the other.

What is the best way to manage the duration of each operation before calling the next one? (for a photo imagine a UIAlertView that dismiss after some seconds delay, for a movie imagine a MPMoviePlayerController instead)

I'm already calling the method that scans the array with an NSOperation.

IMPORTANT: It appears that the MPMovieController does not play (the interface doesn't even appear) whether called inside a NSOperation. Has anyone else experienced this issue?

UPDATE Using performSelectorOnMainThread: makes the MPMoviePlayer work as expected

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

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

发布评论

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

评论(1

风吹雨成花 2024-09-21 13:13:43

这是我设法找到的解决方案。我将其发布在任何人感兴趣的情况下。

首先,我将所有“多媒体操作”放入 NSOperationQueue 中,并将 maxConcurrentOperationCount 设置为 1,因此我确信它们将从主线程异步运行,但仅按照 FIFO 顺序一次一个(这一点非常重要,您希望内容不会在屏幕上重叠)。

然后,对于每个操作,我根据其类别/种类以特定方式激活它。假设存在三种操作:

  1. UIAlertViews 类
  2. MPMoviePlayerController 的
  3. 子类后台操作(不涉及立即出现在当前视图上的多媒体内容的操作

对于前两种,我使用 NSNotifications 来管理队列,因为我不知道内容何时会停止播放或被用户关闭(假设通过触摸),因此对于每个内容,我:

  • 使用 setSuspished:YES 暂停队列
  • 执行 添加一个观察者。相应的 NSNotification
  • 播放内容
  • 播放完毕后发布通知
  • 删除观察者并使用 setSuspended:NO 再次启动队列

对于 UIAlertView,通知会使用 performSelector:withObject:afterDelay:< /code> 表示它应显示的时间量,或者对于 MPMovieController,它会自动启动并命名为 MPMoviePlayerPlaybackDidFinishNotification UIAlertView 和 MP 类型都应在主线程。

第三种可以是简单地执行放入队列中的NSInitationOperation中的一组指令。所以我什至可以创建像“等待”这样的操作来暂停队列执行几秒钟

This is the solution I've managed to find. I'm posting it in the case anyone is interested.

First I put all my 'multimedia actions' in a NSOperationQueue and i set the maxConcurrentOperationCount to 1, so I am certain that they will be run asynchronously from the main thread but only one at a time in a FIFO order (this is very important you you want that your content does not overlap on the screen).

Then for each action I activate it in a particular way depending on its class/kind. Let's suppose there are three kinds of actions:

  1. UIAlertViews subclasses
  2. MPMoviePlayerController-like
  3. Background actions (actions that do not involve multimedia content to appear instantly on the current view

For the first two I use NSNotifications to manage the queue since I do not know when the content will stop playing or will be dismissed by the user (suppose by touch). So for each of those I:

  • Pause the queue execution with setSuspended:YES
  • Add an observer for the corrisponding NSNotification
  • Play the content
  • Post a notification when they finish playing
  • Remove the observer and start the queue again with setSuspended:NO

For an UIAlertView the notification is posted with a performSelector:withObject:afterDelay: saying the amount of time it shall be displayed or after a double tap. For A MPMovieController instead it is launched automatically and is named MPMoviePlayerPlaybackDidFinishNotification. Both the UIAlertView and the MP kind shall be played on the main thread.

The third kind can be a set of instruction simply executed in the NSInvocationOperation put in the queue. So I can even create actions like 'wait' that suspend the queue eecution for some seconds

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