From 89107ec78a880cecf0ad5e7f97c413e50da1299e Mon Sep 17 00:00:00 2001 From: wujianjun Date: Wed, 2 Nov 2016 17:31:22 +0800 Subject: [PATCH] avoid sending same player status through kvo event --- src/DOUAudioEventLoop.m | 9 +++------ src/DOUAudioStreamer.m | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/DOUAudioEventLoop.m b/src/DOUAudioEventLoop.m index 33babbb..4f0e8a0 100644 --- a/src/DOUAudioEventLoop.m +++ b/src/DOUAudioEventLoop.m @@ -352,11 +352,6 @@ - (BOOL)_handleEvent:(event_type)event withStreamer:(DOUAudioStreamer **)streame [[*streamer fileProvider] setEventBlock:_fileProviderEventBlock]; } else if (event == event_provider_events) { - if (*streamer != nil && - [*streamer status] == DOUAudioStreamerBuffering) { - [*streamer setStatus:DOUAudioStreamerPlaying]; - } - [*streamer setBufferingRatio:(double)[[*streamer fileProvider] receivedLength] / [[*streamer fileProvider] expectedLength]]; } else if (event == event_finalizing) { @@ -424,7 +419,8 @@ - (void)_handleStreamer:(DOUAudioStreamer *)streamer return; } - if ([streamer status] != DOUAudioStreamerPlaying) { + if ([streamer status] != DOUAudioStreamerPlaying + && [streamer status] != DOUAudioStreamerBuffering) { return; } @@ -468,6 +464,7 @@ - (void)_handleStreamer:(DOUAudioStreamer *)streamer switch ([[streamer decoder] decodeOnce]) { case DOUAudioDecoderSucceeded: + [streamer setStatus:DOUAudioStreamerPlaying]; break; case DOUAudioDecoderFailed: diff --git a/src/DOUAudioStreamer.m b/src/DOUAudioStreamer.m index c751f5d..9511bec 100644 --- a/src/DOUAudioStreamer.m +++ b/src/DOUAudioStreamer.m @@ -238,4 +238,26 @@ - (void)stop } } +- (void)setStatus:(DOUAudioStreamerStatus)status +{ + if (_status != status) { + [self willChangeValueForKey:@"status"]; + _status = status; + [self didChangeValueForKey:@"status"]; + } +} + +- (DOUAudioStreamerStatus)status +{ + return _status; +} + ++ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key +{ + if ([key isEqualToString:@"status"]) { + return NO; + } + return YES; +} + @end