Skip to content

Commit

Permalink
feat: track populate sibling support
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jun 4, 2023
1 parent 96f04c1 commit 3aeb026
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/provider/proxy_playlist/proxy_playlist_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,38 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
});
}

Future<void> populateSibling() async {}
Future<void> swapSibling(PipedSearchItem video) async {}
Future<void> populateSibling() async {
if (state.activeTrack is SpotubeTrack) {
final activeTrackWithSiblingsForSure =
await (state.activeTrack as SpotubeTrack).populatedCopy();

state = state.copyWith(
tracks: mergeTracks([activeTrackWithSiblingsForSure], state.tracks),
active: state.tracks.toList().indexWhere(
(element) => element.id == activeTrackWithSiblingsForSure.id),
);
}
}

Future<void> swapSibling(PipedSearchItem video) async {
if (state.activeTrack is SpotubeTrack && video is PipedSearchItemStream) {
populateSibling();
final newTrack = await (state.activeTrack as SpotubeTrack)
.swappedCopy(video, preferences);
if (newTrack == null) return;
state = state.copyWith(
tracks: mergeTracks([newTrack], state.tracks),
active: state.tracks
.toList()
.indexWhere((element) => element.id == newTrack.id),
);
await audioPlayer.pause();
await audioPlayer.replaceSource(
audioPlayer.currentSource!,
makeAppropriateSource(newTrack),
);
}
}

Future<void> next() async {
if (audioPlayer.nextSource == null) return;
Expand Down

0 comments on commit 3aeb026

Please sign in to comment.