Skip to content

Commit

Permalink
Fix compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Nov 22, 2020
1 parent 62fe5b6 commit 741facb
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 56 deletions.
81 changes: 44 additions & 37 deletions just_audio/darwin/Classes/AudioPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ @implementation AudioPlayer {
AVQueuePlayer *_player;
AudioSource *_audioSource;
NSMutableArray<IndexedAudioSource *> *_indexedAudioSources;
NSMutableArray<NSNumber *> *_order;
NSArray<NSNumber *> *_order;
NSMutableArray<NSNumber *> *_orderInv;
int _index;
enum ProcessingState _processingState;
Expand Down Expand Up @@ -87,7 +87,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
@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];
Expand All @@ -110,7 +110,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[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(@{});
}];
Expand All @@ -135,6 +135,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
}
}

- (AVQueuePlayer *)player {
return _player;
}

- (float)speed {
return _speed;
}

// Untested
- (void)concatenatingAdd:(NSString *)catId source:(NSDictionary *)source {
[self concatenatingInsertAll:catId index:-1 sources:@[source]];
Expand Down Expand Up @@ -177,7 +185,7 @@ - (void)concatenatingInsertAll:(NSString *)catId index:(int)index sources:(NSArr
}
[self updateOrder];
if (_player.currentItem) {
_index = [self indexForItem:_player.currentItem];
_index = [self indexForItem:(IndexedPlayerItem *)_player.currentItem];
} else {
_index = 0;
}
Expand Down Expand Up @@ -224,7 +232,7 @@ - (void)concatenatingRemoveRange:(NSString *)catId start:(int)start end:(int)end
}
}
[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];
Expand All @@ -244,7 +252,7 @@ - (void)concatenatingMove:(NSString *)catId currentIndex:(int)currentIndex newIn
_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];
}

Expand Down Expand Up @@ -311,7 +319,7 @@ - (void)broadcastPlaybackEvent {
// 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),
});
Expand Down Expand Up @@ -403,7 +411,7 @@ - (AudioSource *)decodeAudioSource:(NSDictionary *)data {
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]) {
Expand All @@ -427,7 +435,7 @@ - (void)enqueueFrom:(int)index {
/* [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];
Expand Down Expand Up @@ -497,7 +505,7 @@ - (void)load:(NSDictionary *)source initialPosition:(CMTime)initialPosition init
}
_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];
Expand Down Expand Up @@ -604,12 +612,12 @@ - (void)updateOrder {
}

- (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");
}

Expand Down Expand Up @@ -812,7 +820,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
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.
Expand Down Expand Up @@ -851,9 +859,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
[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 {
Expand All @@ -872,7 +880,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}

- (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];
Expand Down Expand Up @@ -1025,7 +1033,7 @@ - (void)setShuffleModeEnabled:(BOOL)shuffleModeEnabled {

- (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) {
Expand Down Expand Up @@ -1053,7 +1061,7 @@ - (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void
return;
}
int index = _index;
if (newIndex != [NSNull null]) {
if (newIndex != (id)[NSNull null]) {
index = [newIndex intValue];
}
if (index != _index) {
Expand Down Expand Up @@ -1084,10 +1092,10 @@ - (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void
[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"];
Expand All @@ -1096,18 +1104,18 @@ - (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void
}
}
} 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"];
[self updatePosition];
[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);
Expand Down Expand Up @@ -1140,10 +1148,9 @@ - (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void
[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
Expand All @@ -1152,27 +1159,27 @@ - (void)seek:(CMTime)position index:(NSNumber *)newIndex completionHandler:(void
// 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);
}
Expand Down
2 changes: 1 addition & 1 deletion just_audio/darwin/Classes/AudioSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)m
}
}

- (NSArray *)getShuffleOrder {
- (NSArray<NSNumber *> *)getShuffleOrder {
return @[];
}

Expand Down
6 changes: 3 additions & 3 deletions just_audio/darwin/Classes/ClippingAudioSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ - (instancetype)initWithId:(NSString *)sid audioSource:(UriAudioSource *)audioSo
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;
}

Expand All @@ -39,7 +39,7 @@ - (IndexedPlayerItem *)playerItem {
return _audioSource.playerItem;
}

- (NSArray *)getShuffleOrder {
- (NSArray<NSNumber *> *)getShuffleOrder {
return @[@(0)];
}

Expand Down
18 changes: 9 additions & 9 deletions just_audio/darwin/Classes/ConcatenatingAudioSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ - (instancetype)initWithId:(NSString *)sid audioSources:(NSMutableArray<AudioSou
}

- (int)count {
return _audioSources.count;
return (int)_audioSources.count;
}

- (void)insertSource:(AudioSource *)audioSource atIndex:(int)index {
[_audioSources insertObject:audioSource atIndex:index];
}

- (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];
}
Expand All @@ -50,14 +50,14 @@ - (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)m
}
}

- (NSArray *)getShuffleOrder {
NSMutableArray *order = [NSMutableArray new];
int offset = [order count];
NSMutableArray *childOrders = [NSMutableArray new]; // array of array of ints
- (NSArray<NSNumber *> *)getShuffleOrder {
NSMutableArray<NSNumber *> *order = [NSMutableArray new];
int offset = (int)[order count];
NSMutableArray<NSArray<NSNumber *> *> *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<NSNumber *> *childShuffleOrder = [audioSource getShuffleOrder];
NSMutableArray<NSNumber *> *offsetChildShuffleOrder = [NSMutableArray new];
for (int j = 0; j < [childShuffleOrder count]; j++) {
[offsetChildShuffleOrder addObject:@([childShuffleOrder[j] integerValue] + offset)];
}
Expand Down Expand Up @@ -85,7 +85,7 @@ - (int)shuffle:(int)treeIndex currentIndex:(int)currentIndex {
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);
Expand Down
6 changes: 3 additions & 3 deletions just_audio/darwin/Classes/LoopingAudioSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ - (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)m
}
}

- (NSArray *)getShuffleOrder {
NSMutableArray *order = [NSMutableArray new];
- (NSArray<NSNumber *> *)getShuffleOrder {
NSMutableArray<NSNumber *> *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<NSNumber *> *childShuffleOrder = [audioSource getShuffleOrder];
for (int j = 0; j < [childShuffleOrder count]; j++) {
[order addObject:@([childShuffleOrder[j] integerValue] + offset)];
}
Expand Down
2 changes: 1 addition & 1 deletion just_audio/darwin/Classes/UriAudioSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ - (IndexedPlayerItem *)playerItem {
return _playerItem;
}

- (NSArray *)getShuffleOrder {
- (NSArray<NSNumber *> *)getShuffleOrder {
return @[@(0)];
}

Expand Down
4 changes: 4 additions & 0 deletions just_audio/ios/Classes/AudioPlayer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#import <Flutter/Flutter.h>
#import <AVFoundation/AVFoundation.h>

@interface AudioPlayer : NSObject<FlutterStreamHandler>

@property (readonly, nonatomic) AVQueuePlayer *player;
@property (readonly, nonatomic) float speed;

- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam;
- (void)dispose;

Expand Down
2 changes: 1 addition & 1 deletion just_audio/ios/Classes/AudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- (instancetype)initWithId:(NSString *)sid;
- (int)buildSequence:(NSMutableArray *)sequence treeIndex:(int)treeIndex;
- (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)matches;
- (NSArray *)getShuffleOrder;
- (NSArray<NSNumber *> *)getShuffleOrder;
- (int)shuffle:(int)treeIndex currentIndex:(int)currentIndex;

@end
4 changes: 4 additions & 0 deletions just_audio/macos/Classes/AudioPlayer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#import <FlutterMacOS/FlutterMacOS.h>
#import <AVFoundation/AVFoundation.h>

@interface AudioPlayer : NSObject<FlutterStreamHandler>

@property (readonly, nonatomic) AVQueuePlayer *player;
@property (readonly, nonatomic) float speed;

- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar playerId:(NSString*)idParam;
- (void)dispose;

Expand Down
2 changes: 1 addition & 1 deletion just_audio/macos/Classes/AudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- (instancetype)initWithId:(NSString *)sid;
- (int)buildSequence:(NSMutableArray *)sequence treeIndex:(int)treeIndex;
- (void)findById:(NSString *)sourceId matches:(NSMutableArray<AudioSource *> *)matches;
- (NSArray *)getShuffleOrder;
- (NSArray<NSNumber *> *)getShuffleOrder;
- (int)shuffle:(int)treeIndex currentIndex:(int)currentIndex;

@end

0 comments on commit 741facb

Please sign in to comment.