示例#1
0
文件: Library.cs 项目: yongjan/Espera
 private void RemoveFromPlaylist(Playlist playlist, IEnumerable <Song> songList) => this.RemoveFromPlaylist(playlist, playlist.GetIndexes(songList));
示例#2
0
文件: Library.cs 项目: yongjan/Espera
        private async Task InternPlaySongAsync(int playlistIndex)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            if (this.currentPlayingPlaylist != null && this.currentPlayingPlaylist != this.CurrentPlaylist)
            {
                this.currentPlayingPlaylist.CurrentSongIndex = null;
            }

            this.currentPlayingPlaylist = this.CurrentPlaylist;

            this.CurrentPlaylist.CurrentSongIndex = playlistIndex;

            Song song = this.CurrentPlaylist[playlistIndex].Song;

            try
            {
                await song.PrepareAsync(this.settings.StreamHighestYoutubeQuality?YoutubeStreamingQuality.High : this.settings.YoutubeStreamingQuality)
                .ToObservable().Timeout(Library.PreparationTimeout, RxApp.TaskpoolScheduler);
            }

            catch (SongPreparationException ex)
            {
                this.Log().ErrorException("Failed to prepare song", ex);

                await this.HandleSongCorruptionAsync();

                return;
            }

            catch (TimeoutException ex)
            {
                this.Log().ErrorException("Song preparation timeout", ex);

                await this.HandleSongCorruptionAsync();

                return;
            }

            try
            {
                await this.audioPlayer.LoadAsync(song);
            }

            catch (SongLoadException ex)
            {
                this.Log().ErrorException("Failed to load song", ex);
                song.IsCorrupted = true;

                await this.HandleSongCorruptionAsync();

                return;
            }

            this.audioPlayer.SetVolume(this.Volume);

            try
            {
                await this.audioPlayer.PlayAsync();
            }

            catch (PlaybackException ex)
            {
                this.Log().ErrorException("Failed to play song", ex);
                song.IsCorrupted = true;

                await this.HandleSongCorruptionAsync();

                return;
            }

            song.IsCorrupted = false;
        }