fix: null exception on proxy playlist and audio player

This commit is contained in:
Kingkor Roy Tirtho 2023-05-17 00:30:48 +06:00
parent 696eeee882
commit a455a89c58
3 changed files with 10 additions and 6 deletions

View File

@ -19,7 +19,7 @@ class ProxyPlaylist {
} }
Track? get activeTrack => Track? get activeTrack =>
active == null ? null : tracks.elementAtOrNull(active!); active == null || active == -1 ? null : tracks.elementAtOrNull(active!);
bool get isFetching => bool get isFetching =>
activeTrack != null && activeTrack != null &&

View File

@ -80,6 +80,8 @@ class ProxyPlaylistNotifier extends StateNotifier<ProxyPlaylist>
(element) => element.id == state.activeTrack?.id, (element) => element.id == state.activeTrack?.id,
); );
if (newIndex == -1) return;
state = state.copyWith( state = state.copyWith(
tracks: newlyOrderedTracks.toSet(), tracks: newlyOrderedTracks.toSet(),
active: newIndex, active: newIndex,

View File

@ -74,7 +74,9 @@ class SpotubeAudioPlayer {
.asyncMap( .asyncMap(
(position) async => (await duration)?.inSeconds == 0 (position) async => (await duration)?.inSeconds == 0
? 0 ? 0
: (position.inSeconds / (await duration)!.inSeconds * 100) : (position.inSeconds /
((await duration)?.inSeconds ?? 100) *
100)
.toInt(), .toInt(),
) )
.where((event) => event >= percent) .where((event) => event >= percent)
@ -383,10 +385,10 @@ class SpotubeAudioPlayer {
if (mkSupportedPlatform) { if (mkSupportedPlatform) {
return _mkPlayer!.playlist.medias.map((e) => e.uri).toList(); return _mkPlayer!.playlist.medias.map((e) => e.uri).toList();
} else { } else {
return (_justAudio!.audioSource as ja.ConcatenatingAudioSource) return _justAudio!.sequenceState?.effectiveSequence
.children .map((e) => (e as ja.UriAudioSource).uri.toString())
.map((e) => (e as ja.UriAudioSource).uri.toString()) .toList() ??
.toList(); <String>[];
} }
} }