1

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 ?

slugster
  • 49,403
  • 14
  • 95
  • 145

1 Answers1

1

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];
}
pablasso
  • 2,479
  • 2
  • 26
  • 32
Jane Sales
  • 13,526
  • 3
  • 52
  • 57
  • Thanks for the suggestion and i think that would work. I was already observing that notification but since the content is not going to change after it's queued I figured it would be better to build a **AVMutableComposition**. That also allowed me to add a beep in between items. Seems to work well for my purposes though it ended up being complicated than your suggestion. – Fergal Mohan Aug 15 '11 at 15:42