Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize player's status #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/DOUAudioEventLoop.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -424,7 +419,8 @@ - (void)_handleStreamer:(DOUAudioStreamer *)streamer
return;
}

if ([streamer status] != DOUAudioStreamerPlaying) {
if ([streamer status] != DOUAudioStreamerPlaying
&& [streamer status] != DOUAudioStreamerBuffering) {
return;
}

Expand Down Expand Up @@ -468,6 +464,7 @@ - (void)_handleStreamer:(DOUAudioStreamer *)streamer

switch ([[streamer decoder] decodeOnce]) {
case DOUAudioDecoderSucceeded:
[streamer setStatus:DOUAudioStreamerPlaying];
break;

case DOUAudioDecoderFailed:
Expand Down
22 changes: 22 additions & 0 deletions src/DOUAudioStreamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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