开发者

Using AVQueuePlayer to enforce/respect desired gaps between PlayItems

Hi all I'm using AVQueuePlayer to play a sequence of media files (audio, video). I sometimes have PlayItems that are shorter than the durations I need i.e. I want a silence between some items. I have been considering trying to use some combination of addPeriodicTimeObserverForInterval addBoundaryTimeObserverForTimes or 开发者_开发知识库running my own NSTimer.

It doesn't need to be super accurate + or - 1 Second is acceptable. I'm wondering if there is any collective wisdom out there about these using these API calls to achieve this kind of functionality ?


Why not observe the end of the items, and then, if necessary, start to play again only after a certain delay?

You start to observe the end of an AVPlayerItem like this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playEnded) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];

Then, in your playEnded method, you can decide how long you need to wait, and call another method to start play of the next item after a delay.

-(void)playEnded {
    [self performSelector:@selector(playNextItem) withObject:nil afterDelay:5.0];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜