Skip to content

Commit

Permalink
Fix darwin setVolume before player is created.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanheise committed Jul 19, 2021
1 parent a3875e5 commit b0171bd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions just_audio/darwin/Classes/AudioPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ @implementation AudioPlayer {
LoadControl *_loadControl;
BOOL _playing;
float _speed;
float _volume;
BOOL _justAdvanced;
NSDictionary<NSString *, NSObject *> *_icyMetadata;
}
Expand Down Expand Up @@ -100,6 +101,7 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
_loadControl.preferredPeakBitRate = (NSNumber *)[NSNull null];
}
_speed = 1.0f;
_volume = 1.0f;
_justAdvanced = NO;
_icyMetadata = @{};
__weak __typeof__(self) weakSelf = self;
Expand Down Expand Up @@ -681,6 +683,7 @@ - (void)load:(NSDictionary *)source initialPosition:(CMTime)initialPosition init
if (_playing) {
_player.rate = _speed;
}
[_player setVolume:_volume];
[self broadcastPlaybackEvent];
/* NSLog(@"load:"); */
/* for (int i = 0; i < [_indexedAudioSources count]; i++) { */
Expand Down Expand Up @@ -1053,7 +1056,10 @@ - (void)complete {
}

- (void)setVolume:(float)volume {
[_player setVolume:volume];
_volume = volume;
if (_player) {
[_player setVolume:volume];
}
}

- (void)setSpeed:(float)speed {
Expand Down Expand Up @@ -1084,7 +1090,7 @@ - (void)setSpeed:(float)speed {
// There is no way to reliably query whether the requested speed is
// supported.
_speed = speed;
if (_playing) {
if (_playing && _player) {
_player.rate = speed;
}
[self updatePosition];
Expand Down

0 comments on commit b0171bd

Please sign in to comment.