Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Here's a little background: I have an AVQueuePlayer subclass. It has a method called "playWithDelay", wherein it is to subscribe to receive an AVPlayerItemDidPlayToEndTimeNotification and play its own items with a predefined pause between them. I'm finding that sometimes, though, it pauses about maybe a second into the next item instead. I think it's because AVQueuePlayer plays in its own thread.

Here's my code:

Code:
@implementation DelayQueuePlayer

{

    NSTimeInterval _delay;

}

-(void)playWithDelay:(NSTimeInterval)delay

{

    NSAssert([[self items] count] > 0, @"No items left to play.");

   

    [[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(delayPlay:) name:AVPlayerItemDidPlayToEndTimeNotificationobject:nil];

    _delay = delay;

    [selfcatplay];

}


/** Will pause the player and keep it paused until delay has elapsed. */

-(void)delayPlay:(NSNotification *)notification

{

    // Play the next item.

    [selfperformSelector:@selector(catplay) withObject:nilafterDelay:_delay];

    if ([[selfitems] count] == 0)

    {

        [[NSNotificationCenterdefaultCenter] removeObserver:self];

    }

}


/* Change actionAtItemEnd to allow our AVQueuePlayer to continue playing. */

-(void)changeState

{

    if ([selfactionAtItemEnd] == AVPlayerActionAtItemEndPause) {

        [selfsetActionAtItemEnd:AVPlayerActionAtItemEndAdvance];

    }

    else

    {

        [selfsetActionAtItemEnd:AVPlayerActionAtItemEndPause];

    }

   

}


-(void)catplay

{

    [selfplay];

 [selfchangeState];

}


-(void)removeAllItems

{

    [superremoveAllItems];

    [[NSNotificationCenterdefaultCenter] removeObserver:self];

    [selfchangeState];

}


-(void)removeDelay

{

    @try {

       

        [[NSNotificationCenterdefaultCenter] removeObserver:selfforKeyPath:AVPlayerItemDidPlayToEndTimeNotification];

    }

    @catch(NSException *e) {

    }

   

}

@end

Please help and thank you!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.