From a455a89c5861fd455f6950c7b68beae24bdcc6ed Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Wed, 17 May 2023 00:30:48 +0600 Subject: [PATCH] fix: null exception on proxy playlist and audio player --- lib/provider/proxy_playlist/proxy_playlist.dart | 2 +- .../proxy_playlist/proxy_playlist_provider.dart | 2 ++ lib/services/audio_player/audio_player.dart | 12 +++++++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/provider/proxy_playlist/proxy_playlist.dart b/lib/provider/proxy_playlist/proxy_playlist.dart index c90ddad57..65d2d0201 100644 --- a/lib/provider/proxy_playlist/proxy_playlist.dart +++ b/lib/provider/proxy_playlist/proxy_playlist.dart @@ -19,7 +19,7 @@ class ProxyPlaylist { } Track? get activeTrack => - active == null ? null : tracks.elementAtOrNull(active!); + active == null || active == -1 ? null : tracks.elementAtOrNull(active!); bool get isFetching => activeTrack != null && diff --git a/lib/provider/proxy_playlist/proxy_playlist_provider.dart b/lib/provider/proxy_playlist/proxy_playlist_provider.dart index daff20d77..de5d5d45b 100644 --- a/lib/provider/proxy_playlist/proxy_playlist_provider.dart +++ b/lib/provider/proxy_playlist/proxy_playlist_provider.dart @@ -80,6 +80,8 @@ class ProxyPlaylistNotifier extends StateNotifier (element) => element.id == state.activeTrack?.id, ); + if (newIndex == -1) return; + state = state.copyWith( tracks: newlyOrderedTracks.toSet(), active: newIndex, diff --git a/lib/services/audio_player/audio_player.dart b/lib/services/audio_player/audio_player.dart index 561c97000..d03ba188d 100644 --- a/lib/services/audio_player/audio_player.dart +++ b/lib/services/audio_player/audio_player.dart @@ -74,7 +74,9 @@ class SpotubeAudioPlayer { .asyncMap( (position) async => (await duration)?.inSeconds == 0 ? 0 - : (position.inSeconds / (await duration)!.inSeconds * 100) + : (position.inSeconds / + ((await duration)?.inSeconds ?? 100) * + 100) .toInt(), ) .where((event) => event >= percent) @@ -383,10 +385,10 @@ class SpotubeAudioPlayer { if (mkSupportedPlatform) { return _mkPlayer!.playlist.medias.map((e) => e.uri).toList(); } else { - return (_justAudio!.audioSource as ja.ConcatenatingAudioSource) - .children - .map((e) => (e as ja.UriAudioSource).uri.toString()) - .toList(); + return _justAudio!.sequenceState?.effectiveSequence + .map((e) => (e as ja.UriAudioSource).uri.toString()) + .toList() ?? + []; } }