private void OnMediaEndReached() { if (CanGoNext == false) { if (!Repeat) { OnPlaylistEndReached?.Invoke(); // Don't use the Index property, this would cause the listener to start playback immediately _index = 0; OnCurrentMediaChanged?.Invoke(CurrentMedia, true); return; } Index = 0; } else { Index++; } }
public void Restore() { if (!ApplicationSettingsHelper.Contains(nameof(Index))) { return; } var playlist = BackgroundTrackRepository.LoadPlaylist(); if (!playlist.Any()) { return; } var trackIds = playlist.Select(node => node.TrackId); var restoredplaylist = new SmartCollection <IMediaItem>(); foreach (int trackId in trackIds) { var trackItem = Locator.MediaLibrary.LoadTrackById(trackId); if (trackItem != null) { restoredplaylist.Add(trackItem); } } if (restoredplaylist.Count == 0) { return; } clear(); _playlist = restoredplaylist; OnPlaylistChanged?.Invoke(); _index = (int)ApplicationSettingsHelper.ReadSettingsValue(nameof(Index)); OnCurrentMediaChanged?.Invoke(_playlist[_index], true); }