diff --git a/Audio/Chain/InputNode.m b/Audio/Chain/InputNode.m index 021a90ea5..ae0d81bfb 100644 --- a/Audio/Chain/InputNode.m +++ b/Audio/Chain/InputNode.m @@ -33,6 +33,8 @@ static void *kInputNodeContext = &kInputNodeContext; } - (BOOL)openWithSource:(id)source { + [self removeObservers]; + decoder = [AudioDecoder audioDecoderForSource:source]; if(decoder == nil) @@ -63,6 +65,8 @@ static void *kInputNodeContext = &kInputNodeContext; } - (BOOL)openWithDecoder:(id)d { + [self removeObservers]; + DLog(@"Opening with old decoder: %@", d); decoder = d; diff --git a/Audio/CogPluginMulti.h b/Audio/CogPluginMulti.h index 6eac16c7e..0fed368e4 100644 --- a/Audio/CogPluginMulti.h +++ b/Audio/CogPluginMulti.h @@ -12,6 +12,7 @@ @interface CogDecoderMulti : NSObject { NSArray *theDecoders; id theDecoder; + BOOL observersAdded; } - (id)initWithDecoders:(NSArray *)decoders; diff --git a/Audio/CogPluginMulti.m b/Audio/CogPluginMulti.m index 879705223..54834a0c3 100644 --- a/Audio/CogPluginMulti.m +++ b/Audio/CogPluginMulti.m @@ -113,20 +113,26 @@ static void *kCogDecoderMultiContext = &kCogDecoderMultiContext; } - (void)registerObservers { - [theDecoder addObserver:self - forKeyPath:@"properties" - options:(NSKeyValueObservingOptionNew) - context:kCogDecoderMultiContext]; + if(!observersAdded) { + [theDecoder addObserver:self + forKeyPath:@"properties" + options:(NSKeyValueObservingOptionNew) + context:kCogDecoderMultiContext]; - [theDecoder addObserver:self - forKeyPath:@"metadata" - options:(NSKeyValueObservingOptionNew) - context:kCogDecoderMultiContext]; + [theDecoder addObserver:self + forKeyPath:@"metadata" + options:(NSKeyValueObservingOptionNew) + context:kCogDecoderMultiContext]; + observersAdded = YES; + } } - (void)removeObservers { - [theDecoder removeObserver:self forKeyPath:@"properties" context:kCogDecoderMultiContext]; - [theDecoder removeObserver:self forKeyPath:@"metadata" context:kCogDecoderMultiContext]; + if(observersAdded) { + observersAdded = NO; + [theDecoder removeObserver:self forKeyPath:@"properties" context:kCogDecoderMultiContext]; + [theDecoder removeObserver:self forKeyPath:@"metadata" context:kCogDecoderMultiContext]; + } } - (BOOL)setTrack:(NSURL *)track {