private void Play(MediaPlayerPlaylistItem song, bool playedByUser) { this.jsRuntime.MediaPlayerSetSource(song.PlayableUrl); this.jsRuntime.MediaPlayerPlay(); this.Change(); try { this.apiClient.TelemetrySongPlay( new SongPlayTelemetryRequest { SessionId = this.applicationState.SessionId, SongId = song.Id, PlayedByUser = playedByUser, }); } catch { } }
public void AddAndPlay(MediaPlayerPlaylistItem song) { var existingSong = this.Playlist.FirstOrDefault(x => x.Id == song.Id); if (existingSong != null) { // Song already in the playlist this.CurrentIndexInThePlaylist = this.Playlist.IndexOf(existingSong); } else { this.Playlist.Add(song); this.CurrentIndexInThePlaylist = this.Playlist.Count - 1; } this.Play(song, true); }
public void RemoveSong(MediaPlayerPlaylistItem song) { var songToRemove = this.Playlist.FirstOrDefault(x => x.Id == song.Id); if (songToRemove == null) { return; } var index = this.Playlist.IndexOf(songToRemove); this.Playlist.Remove(songToRemove); if (index < this.CurrentIndexInThePlaylist) { this.CurrentIndexInThePlaylist--; } this.Change(); }