コード例 #1
0
ファイル: RadioService.cs プロジェクト: DevCrafts/MusCat
        public async Task MoveToNextSongAsync()
        {
            if (SongArchive.Count >= MaxSongs)
            {
                SongArchive.RemoveAt(0);
            }

            SongArchive.Add(CurrentSong);
            CurrentSong = UpcomingSongs.First();
            UpcomingSongs.RemoveAt(0);

            await AddRandomSongAsync().ConfigureAwait(false);
        }
コード例 #2
0
ファイル: RadioService.cs プロジェクト: DevCrafts/MusCat
        public void MoveToPrevSong()
        {
            if (!SongArchive.Any())
            {
                return;
            }

            // shrink list of upcoming songs
            UpcomingSongs.Insert(0, CurrentSong);
            UpcomingSongs.Remove(UpcomingSongs.Last());

            // reassign current song (take last song from archive)
            CurrentSong = SongArchive.Last();

            // update archive
            SongArchive.Remove(SongArchive.Last());
        }
コード例 #3
0
ファイル: RadioService.cs プロジェクト: DevCrafts/MusCat
        public void MoveToNextSong()
        {
            // update archive
            if (SongArchive.Count >= MaxSongs)
            {
                SongArchive.RemoveAt(0);
            }

            SongArchive.Add(CurrentSong);

            // reassign current song (take first item from list of upcoming songs)
            CurrentSong = UpcomingSongs.First();

            // update the list of upcoming songs
            UpcomingSongs.RemoveAt(0);
            AddRandomSong();
        }
コード例 #4
0
        /// <summary>
        /// Switching to previous song is done synchronously
        /// since his operation is very cheap (just recombinate songs in collections)
        /// </summary>
        public Task MoveToPrevSongAsync()
        {
            if (SongArchive.Any())
            {
                // shrink list of upcoming songs
                UpcomingSongs.Insert(0, CurrentSong);
                UpcomingSongs.Remove(UpcomingSongs.Last());

                // reassign current song (take last song from archive)
                CurrentSong = SongArchive.Last();

                // update archive
                SongArchive.Remove(SongArchive.Last());
            }

            return(Task.CompletedTask);
        }
コード例 #5
0
ファイル: RadioService.cs プロジェクト: DevCrafts/MusCat
        /// <summary>
        /// Same as synchronous version but with async calls to EF
        /// </summary>
        private async Task <Song> SelectRandomSongAsync(int maxAttempts = 15)
        {
            var attempts = 0;

            Song song;

            // keep selecting song randomly until the song file is actually present in the file system...
            // ...and while it isn't present in archive of recently played songs and upcoming songs
            do
            {
                if (attempts++ == maxAttempts)
                {
                    return(_songSelector.DefaultSong());
                }
                song = await _songSelector.SelectSongAsync().ConfigureAwait(false);
            }while (SongArchive.Any(s => s.Id == song.Id) || // true, if the archive already contains this song
                    UpcomingSongs.Any(s => s.Id == song.Id) || // true, if it is already in songlist
                    song.Id == CurrentSong.Id ||             // true, if it's currently playing
                    FileLocator.FindSongPath(song) == "");   // true, if the file with this song doesn't exist

            return(song);
        }
コード例 #6
0
ファイル: RadioService.cs プロジェクト: DevCrafts/MusCat
 public void AddToArchive() => SongArchive.Add(CurrentSong);