StreetVoice / HysteriaPlayer

Objective-C audio player, sitting on top of AVPlayer
Other
583 stars 99 forks source link

Delegate message when play empty sound #101

Closed iTSangarDEV closed 8 years ago

iTSangarDEV commented 8 years ago

Is necessary send delegate message hysteriaPlayerCurrentItemChanged when emptySoundPlaying is YES?

if (newPlayerItem != (id)[NSNull null]) {
        [newPlayerItem addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];
        [newPlayerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];

        if ([self.delegate respondsToSelector:@selector(hysteriaPlayerCurrentItemChanged:)]) {
                [self.delegate hysteriaPlayerCurrentItemChanged:newPlayerItem];
        }
            self.emptySoundPlaying = NO;
 }

can be?

if ([self.delegate respondsToSelector:@selector(hysteriaPlayerCurrentItemChanged:)] && !self.emptySoundPlaying) {
            [self.delegate hysteriaPlayerCurrentItemChanged:newPlayerItem];
}
saiday commented 8 years ago

Empty sound is a hack for buffering long term first remote item, is there any reason that you want to handle it?

iTSangarDEV commented 8 years ago

As empty sound is not a real sound and finality of method hysteriaPlayerCurrentItemChanged: is usually update the interface, so I think that can be called only when real item is changed.

I found this necessity when trying transform result of getHysteriaIndex: in Integer on Swift and empty sound return null

let index = Int(hysteriaPlayer.getHysteriaIndex(hysteriaPlayer.getCurrentItem()))
iTSangarDEV commented 8 years ago

But looking around I found solution for check if is null (emptySoundPlaying == YES):

if let index: NSNumber = hysteriaPlayer.getHysteriaIndex(hysteriaPlayer.getCurrentItem()) {
  // now I can use Int(index)
}

Thank you for helping me to think better what I wanted, you can close this issue.

saiday commented 8 years ago

Yeah, great approach to find index. Glad to hear that.