diff --git a/lib/src/player/player_model.dart b/lib/src/player/player_model.dart index 74a9b9a2f..a9bded9b3 100644 --- a/lib/src/player/player_model.dart +++ b/lib/src/player/player_model.dart @@ -64,7 +64,7 @@ class PlayerModel extends SafeChangeNotifier { bool get shuffle => service.shuffle; void setShuffle(bool value) => service.setShuffle(value); - double get volume => service.volume; + double? get volume => service.volume; Future setVolume(double value) async => await service.setVolume(value); double get rate => service.rate; diff --git a/lib/src/player/player_service.dart b/lib/src/player/player_service.dart index e6c0b243a..5dea979d6 100644 --- a/lib/src/player/player_service.dart +++ b/lib/src/player/player_service.dart @@ -173,8 +173,8 @@ class PlayerService { final _volumeController = StreamController.broadcast(); Stream get volumeChanged => _volumeController.stream; - double _volume = 100.0; - double get volume => _volume; + double? _volume; + double? get volume => _volume; Future setVolume(double value) async { if (value == _volume) return; await _player.setVolume(value); @@ -209,11 +209,12 @@ class PlayerService { _player.state.tracks; }); if (newPosition != null && _audio!.audioType != AudioType.radio) { + final tempVol = _volume; _player.setVolume(0).then( (_) => Future.delayed(const Duration(seconds: 3)).then( (_) => _player .seek(newPosition) - .then((_) => _player.setVolume(100.0)), + .then((_) => _player.setVolume(tempVol ?? 100.0)), ), ); } @@ -247,8 +248,6 @@ class PlayerService { Future init() async { await _initMediaControl(); - await _readPlayerState(); - _isPlayingSub = _player.stream.playing.listen((value) { setIsPlaying(value); }); @@ -294,6 +293,8 @@ class PlayerService { } } }); + + await _readPlayerState(); } Future playNext() async { diff --git a/lib/src/player/volume_popup.dart b/lib/src/player/volume_popup.dart index e230ebbf0..98b031500 100644 --- a/lib/src/player/volume_popup.dart +++ b/lib/src/player/volume_popup.dart @@ -21,11 +21,11 @@ class VolumeSliderPopup extends StatelessWidget with WatchItMixin { final volume = watchPropertyValue((PlayerModel m) => m.volume); final setVolume = playerModel.setVolume; IconData iconData; - if (volume <= 0) { + if (volume != null && volume <= 0) { iconData = Iconz().speakerMutedFilled; - } else if (volume <= 20) { + } else if (volume != null && volume <= 20) { iconData = Iconz().speakerLowFilled; - } else if (volume <= 50 && volume > 20) { + } else if (volume != null && volume <= 50 && volume > 20) { iconData = Iconz().speakerMediumFilled; } else { iconData = Iconz().speakerHighFilled; @@ -66,7 +66,7 @@ class _Slider extends StatelessWidget with WatchItMixin { return RotatedBox( quarterTurns: 3, child: Slider( - value: volume, + value: volume ?? 100.0, onChanged: setVolume, max: 100, min: 0,