private async Task PlayFile(string fileName, SongChangedType changedType, Func<bool> newAutoPlayValue) { if (fileName == null) { BackgroundMediaPlayer.Current.Pause(); BackgroundMediaPlayer.Current.Position = TimeSpan.Zero; ApplicationSettings.CurrentSongFileName.Save(null); fileName = await playlistManager.GetCurrentFileToPlay(); newAutoPlayValue = () => false; } if (fileName != null) { ApplicationSettings.CurrentSongFileName.Save(fileName); this.SendToForeground(CommunicationConstants.PlaybackNewSong, changedType.ToString()); var file = await StorageFile.GetFileFromPathAsync(fileName); this.nowPlayingFileName = fileName; var autoplay = newAutoPlayValue(); BackgroundMediaPlayer.Current.AutoPlay = autoplay; BackgroundMediaPlayer.Current.SetFileSource(file); UpdateMediaControls(file); } }
private async Task PlayCurrentSong(bool forceAutoplay, SongChangedType songChangedType) { if (playlistManager == null) return; await this.PlayFile( await playlistManager.GetCurrentFileToPlay(), songChangedType, () => forceAutoplay || BackgroundMediaPlayer.Current.CurrentState != MediaPlayerState.Paused); }
public CurrentSongChangedEventArgs(SongChangedType type) { this.Type = type; }