按顺序播放多媒体内容
您好,我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我设法找到的解决方案。我将其发布在任何人感兴趣的情况下。
首先,我将所有“多媒体操作”放入 NSOperationQueue 中,并将 maxConcurrentOperationCount 设置为 1,因此我确信它们将从主线程异步运行,但仅按照 FIFO 顺序一次一个(这一点非常重要,您希望内容不会在屏幕上重叠)。
然后,对于每个操作,我根据其类别/种类以特定方式激活它。假设存在三种操作:
对于前两种,我使用 NSNotifications 来管理队列,因为我不知道内容何时会停止播放或被用户关闭(假设通过触摸),因此对于每个内容,我:
setSuspished:YES
暂停队列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 themaxConcurrentOperationCount
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:
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:setSuspended:YES
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 namedMPMoviePlayerPlaybackDidFinishNotification
. 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