State checking on iOS/macOS

This commit is contained in:
Ryan Heise 2020-09-28 03:06:08 +10:00
parent 38ed64293d
commit 8ab57c6e5c
1 changed files with 9 additions and 1 deletions

View File

@ -354,6 +354,7 @@
[playerItem removeObserver:self forKeyPath:@"status"]; [playerItem removeObserver:self forKeyPath:@"status"];
[playerItem removeObserver:self forKeyPath:@"playbackBufferEmpty"]; [playerItem removeObserver:self forKeyPath:@"playbackBufferEmpty"];
[playerItem removeObserver:self forKeyPath:@"playbackBufferFull"]; [playerItem removeObserver:self forKeyPath:@"playbackBufferFull"];
[playerItem removeObserver:self forKeyPath:@"loadedTimeRanges"];
//[playerItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"]; //[playerItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp"];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemFailedToPlayToEndTimeNotification object:playerItem]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemFailedToPlayToEndTimeNotification object:playerItem];
@ -484,7 +485,7 @@
} }
- (void)load:(NSDictionary *)source result:(FlutterResult)result { - (void)load:(NSDictionary *)source result:(FlutterResult)result {
if (!_playing) { if (_playing) {
[_player pause]; [_player pause];
} }
if (_processingState == loading) { if (_processingState == loading) {
@ -892,6 +893,7 @@
} }
- (void)play:(FlutterResult)result { - (void)play:(FlutterResult)result {
if (_playing) return;
if (result) { if (result) {
if (_playResult) { if (_playResult) {
NSLog(@"INTERRUPTING PLAY"); NSLog(@"INTERRUPTING PLAY");
@ -917,6 +919,7 @@
} }
- (void)pause { - (void)pause {
if (!_playing) return;
_playing = NO; _playing = NO;
[_player pause]; [_player pause];
[self updatePosition]; [self updatePosition];
@ -1003,6 +1006,9 @@
} }
- (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void (^)(BOOL))completionHandler { - (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void (^)(BOOL))completionHandler {
if (_processingState == none || _processingState == loading) {
return;
}
int index = _index; int index = _index;
if (newIndex != [NSNull null]) { if (newIndex != [NSNull null]) {
index = [newIndex intValue]; index = [newIndex intValue];
@ -1131,6 +1137,7 @@
} }
- (void)dispose { - (void)dispose {
if (!_player) return;
if (_processingState != none) { if (_processingState != none) {
[_player pause]; [_player pause];
_processingState = none; _processingState = none;
@ -1145,6 +1152,7 @@
[self removeItemObservers:_indexedAudioSources[i].playerItem]; [self removeItemObservers:_indexedAudioSources[i].playerItem];
} }
} }
_audioSource = nil;
if (_player) { if (_player) {
[_player removeObserver:self forKeyPath:@"currentItem"]; [_player removeObserver:self forKeyPath:@"currentItem"];
if (@available(macOS 10.12, iOS 10.0, *)) { if (@available(macOS 10.12, iOS 10.0, *)) {