From 741facb0dc4ff1a333f7e721512c1b84ef65cb2f Mon Sep 17 00:00:00 2001 From: Ryan Heise Date: Sun, 22 Nov 2020 15:03:10 +1100 Subject: [PATCH] Fix compiler warnings. --- just_audio/darwin/Classes/AudioPlayer.m | 81 ++++++++++--------- just_audio/darwin/Classes/AudioSource.m | 2 +- .../darwin/Classes/ClippingAudioSource.m | 6 +- .../darwin/Classes/ConcatenatingAudioSource.m | 18 ++--- .../darwin/Classes/LoopingAudioSource.m | 6 +- just_audio/darwin/Classes/UriAudioSource.m | 2 +- just_audio/ios/Classes/AudioPlayer.h | 4 + just_audio/ios/Classes/AudioSource.h | 2 +- just_audio/macos/Classes/AudioPlayer.h | 4 + just_audio/macos/Classes/AudioSource.h | 2 +- 10 files changed, 71 insertions(+), 56 deletions(-) diff --git a/just_audio/darwin/Classes/AudioPlayer.m b/just_audio/darwin/Classes/AudioPlayer.m index fef0e3a..0a7350b 100644 --- a/just_audio/darwin/Classes/AudioPlayer.m +++ b/just_audio/darwin/Classes/AudioPlayer.m @@ -20,7 +20,7 @@ AVQueuePlayer *_player; AudioSource *_audioSource; NSMutableArray *_indexedAudioSources; - NSMutableArray *_order; + NSArray *_order; NSMutableArray *_orderInv; int _index; enum ProcessingState _processingState; @@ -87,7 +87,7 @@ @try { NSDictionary *request = (NSDictionary *)call.arguments; if ([@"load" isEqualToString:call.method]) { - CMTime initialPosition = request[@"initialPosition"] == [NSNull null] ? kCMTimeZero : CMTimeMake([request[@"initialPosition"] longLongValue], 1000000); + CMTime initialPosition = request[@"initialPosition"] == (id)[NSNull null] ? kCMTimeZero : CMTimeMake([request[@"initialPosition"] longLongValue], 1000000); [self load:request[@"audioSource"] initialPosition:initialPosition initialIndex:request[@"initialIndex"] result:result]; } else if ([@"play" isEqualToString:call.method]) { [self play:result]; @@ -110,7 +110,7 @@ [self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[request[@"enabled"] boolValue]]; result(@{}); } else if ([@"seek" isEqualToString:call.method]) { - CMTime position = request[@"position"] == [NSNull null] ? kCMTimePositiveInfinity : CMTimeMake([request[@"position"] longLongValue], 1000000); + CMTime position = request[@"position"] == (id)[NSNull null] ? kCMTimePositiveInfinity : CMTimeMake([request[@"position"] longLongValue], 1000000); [self seek:position index:request[@"index"] completionHandler:^(BOOL finished) { result(@{}); }]; @@ -135,6 +135,14 @@ } } +- (AVQueuePlayer *)player { + return _player; +} + +- (float)speed { + return _speed; +} + // Untested - (void)concatenatingAdd:(NSString *)catId source:(NSDictionary *)source { [self concatenatingInsertAll:catId index:-1 sources:@[source]]; @@ -177,7 +185,7 @@ } [self updateOrder]; if (_player.currentItem) { - _index = [self indexForItem:_player.currentItem]; + _index = [self indexForItem:(IndexedPlayerItem *)_player.currentItem]; } else { _index = 0; } @@ -224,7 +232,7 @@ } } [self updateOrder]; - if (_index >= _indexedAudioSources.count) _index = _indexedAudioSources.count - 1; + if (_index >= _indexedAudioSources.count) _index = (int)_indexedAudioSources.count - 1; if (_index < 0) _index = 0; [self enqueueFrom:_index]; [self broadcastPlaybackEvent]; @@ -244,7 +252,7 @@ _indexedAudioSources = [[NSMutableArray alloc] init]; [_audioSource buildSequence:_indexedAudioSources treeIndex:0]; [self updateOrder]; - [self enqueueFrom:[self indexForItem:_player.currentItem]]; + [self enqueueFrom:[self indexForItem:(IndexedPlayerItem *)_player.currentItem]]; [self broadcastPlaybackEvent]; } @@ -311,7 +319,7 @@ // TODO: buffer position @"bufferedPosition": @((long long)1000 * _updatePosition), // TODO: Icy Metadata - @"icyMetadata": [NSNull null], + @"icyMetadata": (id)[NSNull null], @"duration": @((long long)1000 * [self getDuration]), @"currentIndex": @(_index), }); @@ -403,7 +411,7 @@ audioSources:[self decodeAudioSources:data[@"children"]]]; } else if ([@"clipping" isEqualToString:type]) { return [[ClippingAudioSource alloc] initWithId:data[@"id"] - audioSource:[self decodeAudioSource:data[@"child"]] + audioSource:(UriAudioSource *)[self decodeAudioSource:data[@"child"]] start:data[@"start"] end:data[@"end"]]; } else if ([@"looping" isEqualToString:type]) { @@ -427,7 +435,7 @@ /* [self dumpQueue]; */ // First, remove all _player items except for the currently playing one (if any). - IndexedPlayerItem *oldItem = _player.currentItem; + IndexedPlayerItem *oldItem = (IndexedPlayerItem *)_player.currentItem; IndexedPlayerItem *existingItem = nil; IndexedPlayerItem *newItem = _indexedAudioSources.count > 0 ? _indexedAudioSources[_index].playerItem : nil; NSArray *oldPlayerItems = [NSArray arrayWithArray:_player.items]; @@ -497,7 +505,7 @@ } _initialPos = initialPosition; _loadResult = result; - _index = (initialIndex != [NSNull null]) ? [initialIndex intValue] : 0; + _index = (initialIndex != (id)[NSNull null]) ? [initialIndex intValue] : 0; _processingState = loading; [self updatePosition]; [self broadcastPlaybackEvent]; @@ -604,12 +612,12 @@ } - (void)onItemStalled:(NSNotification *)notification { - IndexedPlayerItem *playerItem = (IndexedPlayerItem *)notification.object; + //IndexedPlayerItem *playerItem = (IndexedPlayerItem *)notification.object; NSLog(@"onItemStalled"); } - (void)onFailToComplete:(NSNotification *)notification { - IndexedPlayerItem *playerItem = (IndexedPlayerItem *)notification.object; + //IndexedPlayerItem *playerItem = (IndexedPlayerItem *)notification.object; NSLog(@"onFailToComplete"); } @@ -812,7 +820,7 @@ } return; } else { - int expectedIndex = [self indexForItem:_player.currentItem]; + int expectedIndex = [self indexForItem:(IndexedPlayerItem *)_player.currentItem]; if (_index != expectedIndex) { // AVQueuePlayer will sometimes skip over error items without // notifying this observer. @@ -851,9 +859,9 @@ [weakSelf updatePosition]; [weakSelf broadcastPlaybackEvent]; if (shouldResumePlayback) { - _player.actionAtItemEnd = originalEndAction; + weakSelf.player.actionAtItemEnd = originalEndAction; // TODO: This logic is almost duplicated in seek. See if we can reuse this code. - _player.rate = _speed; + weakSelf.player.rate = weakSelf.speed; } }]; } else { @@ -872,7 +880,7 @@ } - (void)sendErrorForItem:(IndexedPlayerItem *)playerItem { - FlutterError *flutterError = [FlutterError errorWithCode:[NSString stringWithFormat:@"%d", playerItem.error.code] + FlutterError *flutterError = [FlutterError errorWithCode:[NSString stringWithFormat:@"%d", (int)playerItem.error.code] message:playerItem.error.localizedDescription details:nil]; [self sendError:flutterError playerItem:playerItem]; @@ -1025,7 +1033,7 @@ - (void)dumpQueue { for (int i = 0; i < _player.items.count; i++) { - IndexedPlayerItem *playerItem = _player.items[i]; + IndexedPlayerItem *playerItem = (IndexedPlayerItem *)_player.items[i]; for (int j = 0; j < _indexedAudioSources.count; j++) { IndexedAudioSource *source = _indexedAudioSources[j]; if (source.playerItem == playerItem) { @@ -1053,7 +1061,7 @@ return; } int index = _index; - if (newIndex != [NSNull null]) { + if (newIndex != (id)[NSNull null]) { index = [newIndex intValue]; } if (index != _index) { @@ -1084,10 +1092,10 @@ [self broadcastPlaybackEvent]; [source seek:position completionHandler:^(BOOL finished) { if (@available(macOS 10.12, iOS 10.0, *)) { - if (_playing) { + if (self->_playing) { // Handled by timeControlStatus } else { - if (_bufferUnconfirmed && !_player.currentItem.playbackBufferFull) { + if (self->_bufferUnconfirmed && !self->_player.currentItem.playbackBufferFull) { // Stay in buffering } else if (source.playerItem.status == AVPlayerItemStatusReadyToPlay) { [self leaveBuffering:@"seek to index finished, (!bufferUnconfirmed || playbackBufferFull) && ready to play"]; @@ -1096,7 +1104,7 @@ } } } else { - if (_bufferUnconfirmed && !_player.currentItem.playbackBufferFull) { + if (self->_bufferUnconfirmed && !self->_player.currentItem.playbackBufferFull) { // Stay in buffering } else if (source.playerItem.status == AVPlayerItemStatusReadyToPlay) { [self leaveBuffering:@"seek to index finished, (!bufferUnconfirmed || playbackBufferFull) && ready to play"]; @@ -1104,10 +1112,10 @@ [self broadcastPlaybackEvent]; } } - if (_playing) { - _player.rate = _speed; + if (self->_playing) { + self->_player.rate = self->_speed; } - _seekPos = kCMTimeInvalid; + self->_seekPos = kCMTimeInvalid; [self broadcastPlaybackEvent]; if (completionHandler) { completionHandler(finished); @@ -1140,10 +1148,9 @@ [self enterBuffering:@"seek"]; [self updatePosition]; [self broadcastPlaybackEvent]; - __weak __typeof__(self) weakSelf = self; [_indexedAudioSources[_index] seek:position completionHandler:^(BOOL finished) { - [weakSelf updatePosition]; - if (_playing) { + [self updatePosition]; + if (self->_playing) { // If playing, buffering will be detected either by: // 1. checkForDiscontinuity // 2. timeControlStatus @@ -1152,27 +1159,27 @@ // detect buffering when buffered audio is not immediately // available. //[_player playImmediatelyAtRate:_speed]; - _player.rate = _speed; + self->_player.rate = self->_speed; } else { - _player.rate = _speed; + self->_player.rate = self->_speed; } } else { // If not playing, there is no reliable way to detect // when buffering has completed, so we use // !playbackBufferEmpty. Although this always seems to // be full even right after a seek. - if (_player.currentItem.playbackBufferEmpty) { - [weakSelf enterBuffering:@"seek finished, playbackBufferEmpty"]; + if (self->_player.currentItem.playbackBufferEmpty) { + [self enterBuffering:@"seek finished, playbackBufferEmpty"]; } else { - [weakSelf leaveBuffering:@"seek finished, !playbackBufferEmpty"]; + [self leaveBuffering:@"seek finished, !playbackBufferEmpty"]; } - [weakSelf updatePosition]; - if (_processingState != buffering) { - [weakSelf broadcastPlaybackEvent]; + [self updatePosition]; + if (self->_processingState != buffering) { + [self broadcastPlaybackEvent]; } } - _seekPos = kCMTimeInvalid; - [weakSelf broadcastPlaybackEvent]; + self->_seekPos = kCMTimeInvalid; + [self broadcastPlaybackEvent]; if (completionHandler) { completionHandler(finished); } diff --git a/just_audio/darwin/Classes/AudioSource.m b/just_audio/darwin/Classes/AudioSource.m index 81534f1..d615af8 100644 --- a/just_audio/darwin/Classes/AudioSource.m +++ b/just_audio/darwin/Classes/AudioSource.m @@ -26,7 +26,7 @@ } } -- (NSArray *)getShuffleOrder { +- (NSArray *)getShuffleOrder { return @[]; } diff --git a/just_audio/darwin/Classes/ClippingAudioSource.m b/just_audio/darwin/Classes/ClippingAudioSource.m index 0adf872..36b2ed9 100644 --- a/just_audio/darwin/Classes/ClippingAudioSource.m +++ b/just_audio/darwin/Classes/ClippingAudioSource.m @@ -14,8 +14,8 @@ self = [super initWithId:sid]; NSAssert(self, @"super init cannot be nil"); _audioSource = audioSource; - _start = start == [NSNull null] ? kCMTimeZero : CMTimeMake([start longLongValue], 1000000); - _end = end == [NSNull null] ? kCMTimeInvalid : CMTimeMake([end longLongValue], 1000000); + _start = start == (id)[NSNull null] ? kCMTimeZero : CMTimeMake([start longLongValue], 1000000); + _end = end == (id)[NSNull null] ? kCMTimeInvalid : CMTimeMake([end longLongValue], 1000000); return self; } @@ -39,7 +39,7 @@ return _audioSource.playerItem; } -- (NSArray *)getShuffleOrder { +- (NSArray *)getShuffleOrder { return @[@(0)]; } diff --git a/just_audio/darwin/Classes/ConcatenatingAudioSource.m b/just_audio/darwin/Classes/ConcatenatingAudioSource.m index bd7b713..e1dea15 100644 --- a/just_audio/darwin/Classes/ConcatenatingAudioSource.m +++ b/just_audio/darwin/Classes/ConcatenatingAudioSource.m @@ -16,7 +16,7 @@ } - (int)count { - return _audioSources.count; + return (int)_audioSources.count; } - (void)insertSource:(AudioSource *)audioSource atIndex:(int)index { @@ -24,7 +24,7 @@ } - (void)removeSourcesFromIndex:(int)start toIndex:(int)end { - if (end == -1) end = _audioSources.count; + if (end == -1) end = (int)_audioSources.count; for (int i = start; i < end; i++) { [_audioSources removeObjectAtIndex:start]; } @@ -50,14 +50,14 @@ } } -- (NSArray *)getShuffleOrder { - NSMutableArray *order = [NSMutableArray new]; - int offset = [order count]; - NSMutableArray *childOrders = [NSMutableArray new]; // array of array of ints +- (NSArray *)getShuffleOrder { + NSMutableArray *order = [NSMutableArray new]; + int offset = (int)[order count]; + NSMutableArray *> *childOrders = [NSMutableArray new]; // array of array of ints for (int i = 0; i < [_audioSources count]; i++) { AudioSource *audioSource = _audioSources[i]; - NSArray *childShuffleOrder = [audioSource getShuffleOrder]; - NSMutableArray *offsetChildShuffleOrder = [NSMutableArray new]; + NSArray *childShuffleOrder = [audioSource getShuffleOrder]; + NSMutableArray *offsetChildShuffleOrder = [NSMutableArray new]; for (int j = 0; j < [childShuffleOrder count]; j++) { [offsetChildShuffleOrder addObject:@([childShuffleOrder[j] integerValue] + offset)]; } @@ -85,7 +85,7 @@ for (int i = 0; i < [_audioSources count]; i++) { [_shuffleOrder addObject:@(0)]; } - NSLog(@"shuffle: audioSources.count=%d and shuffleOrder.count=%d", [_audioSources count], [_shuffleOrder count]); + NSLog(@"shuffle: audioSources.count=%d and shuffleOrder.count=%d", (int)[_audioSources count], (int)[_shuffleOrder count]); // First generate a random shuffle for (int i = 0; i < [_audioSources count]; i++) { int j = arc4random_uniform(i + 1); diff --git a/just_audio/darwin/Classes/LoopingAudioSource.m b/just_audio/darwin/Classes/LoopingAudioSource.m index ba4b52b..56e5040 100644 --- a/just_audio/darwin/Classes/LoopingAudioSource.m +++ b/just_audio/darwin/Classes/LoopingAudioSource.m @@ -28,12 +28,12 @@ } } -- (NSArray *)getShuffleOrder { - NSMutableArray *order = [NSMutableArray new]; +- (NSArray *)getShuffleOrder { + NSMutableArray *order = [NSMutableArray new]; int offset = (int)[order count]; for (int i = 0; i < [_audioSources count]; i++) { AudioSource *audioSource = _audioSources[i]; - NSArray *childShuffleOrder = [audioSource getShuffleOrder]; + NSArray *childShuffleOrder = [audioSource getShuffleOrder]; for (int j = 0; j < [childShuffleOrder count]; j++) { [order addObject:@([childShuffleOrder[j] integerValue] + offset)]; } diff --git a/just_audio/darwin/Classes/UriAudioSource.m b/just_audio/darwin/Classes/UriAudioSource.m index f03aa9e..7ca975a 100644 --- a/just_audio/darwin/Classes/UriAudioSource.m +++ b/just_audio/darwin/Classes/UriAudioSource.m @@ -35,7 +35,7 @@ return _playerItem; } -- (NSArray *)getShuffleOrder { +- (NSArray *)getShuffleOrder { return @[@(0)]; } diff --git a/just_audio/ios/Classes/AudioPlayer.h b/just_audio/ios/Classes/AudioPlayer.h index 42d81e1..2f03d13 100644 --- a/just_audio/ios/Classes/AudioPlayer.h +++ b/just_audio/ios/Classes/AudioPlayer.h @@ -1,7 +1,11 @@ #import +#import @interface AudioPlayer : NSObject +@property (readonly, nonatomic) AVQueuePlayer *player; +@property (readonly, nonatomic) float speed; + - (instancetype)initWithRegistrar:(NSObject *)registrar playerId:(NSString*)idParam; - (void)dispose; diff --git a/just_audio/ios/Classes/AudioSource.h b/just_audio/ios/Classes/AudioSource.h index c192f33..bc7f33e 100644 --- a/just_audio/ios/Classes/AudioSource.h +++ b/just_audio/ios/Classes/AudioSource.h @@ -7,7 +7,7 @@ - (instancetype)initWithId:(NSString *)sid; - (int)buildSequence:(NSMutableArray *)sequence treeIndex:(int)treeIndex; - (void)findById:(NSString *)sourceId matches:(NSMutableArray *)matches; -- (NSArray *)getShuffleOrder; +- (NSArray *)getShuffleOrder; - (int)shuffle:(int)treeIndex currentIndex:(int)currentIndex; @end diff --git a/just_audio/macos/Classes/AudioPlayer.h b/just_audio/macos/Classes/AudioPlayer.h index 1ce2109..c5637e3 100644 --- a/just_audio/macos/Classes/AudioPlayer.h +++ b/just_audio/macos/Classes/AudioPlayer.h @@ -1,7 +1,11 @@ #import +#import @interface AudioPlayer : NSObject +@property (readonly, nonatomic) AVQueuePlayer *player; +@property (readonly, nonatomic) float speed; + - (instancetype)initWithRegistrar:(NSObject *)registrar playerId:(NSString*)idParam; - (void)dispose; diff --git a/just_audio/macos/Classes/AudioSource.h b/just_audio/macos/Classes/AudioSource.h index 3dd1bf5..368a457 100644 --- a/just_audio/macos/Classes/AudioSource.h +++ b/just_audio/macos/Classes/AudioSource.h @@ -7,7 +7,7 @@ - (instancetype)initWithId:(NSString *)sid; - (int)buildSequence:(NSMutableArray *)sequence treeIndex:(int)treeIndex; - (void)findById:(NSString *)sourceId matches:(NSMutableArray *)matches; -- (NSArray *)getShuffleOrder; +- (NSArray *)getShuffleOrder; - (int)shuffle:(int)treeIndex currentIndex:(int)currentIndex; @end