Skip to content

Commit

Permalink
fix: null exception on proxy playlist and audio player
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingkor Roy Tirtho committed May 16, 2023
1 parent 696eeee commit a455a89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/provider/proxy_playlist/proxy_playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 2 additions & 0 deletions lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ProxyPlaylistNotifier extends StateNotifier<ProxyPlaylist>
(element) => element.id == state.activeTrack?.id,
);

if (newIndex == -1) return;

state = state.copyWith(
tracks: newlyOrderedTracks.toSet(),
active: newIndex,
Expand Down
12 changes: 7 additions & 5 deletions lib/services/audio_player/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() ??
<String>[];
}
}

Expand Down

0 comments on commit a455a89

Please sign in to comment.