diff --git a/lib/provider/proxy_playlist/proxy_playlist_provider.dart b/lib/provider/proxy_playlist/proxy_playlist_provider.dart index 7efcfb7d3..70fdffcdb 100644 --- a/lib/provider/proxy_playlist/proxy_playlist_provider.dart +++ b/lib/provider/proxy_playlist/proxy_playlist_provider.dart @@ -304,8 +304,38 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier }); } - Future populateSibling() async {} - Future swapSibling(PipedSearchItem video) async {} + Future 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 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 next() async { if (audioPlayer.nextSource == null) return;