[Event Handler] Fix observers for reused classes
Fix class handling so it cleans up observers if the InputNode is reused. Signed-off-by: Christopher Snowhill <kode54@gmail.com>swiftingly
parent
789e8e432e
commit
7bc49ccb80
|
@ -33,6 +33,8 @@ static void *kInputNodeContext = &kInputNodeContext;
|
|||
}
|
||||
|
||||
- (BOOL)openWithSource:(id<CogSource>)source {
|
||||
[self removeObservers];
|
||||
|
||||
decoder = [AudioDecoder audioDecoderForSource:source];
|
||||
|
||||
if(decoder == nil)
|
||||
|
@ -63,6 +65,8 @@ static void *kInputNodeContext = &kInputNodeContext;
|
|||
}
|
||||
|
||||
- (BOOL)openWithDecoder:(id<CogDecoder>)d {
|
||||
[self removeObservers];
|
||||
|
||||
DLog(@"Opening with old decoder: %@", d);
|
||||
decoder = d;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
@interface CogDecoderMulti : NSObject <CogDecoder> {
|
||||
NSArray *theDecoders;
|
||||
id<CogDecoder> theDecoder;
|
||||
BOOL observersAdded;
|
||||
}
|
||||
|
||||
- (id)initWithDecoders:(NSArray *)decoders;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue