Пример #1
0
        public void Skip()
        {
            if (PlayQueue.Count == 0)
            {
                Stop(); //no more songs
                return;
            }

            Stop();
            OnSongfinished();
            CurrentSong = PlayQueue.Dequeue();
            PlayedSongs.Enqueue(CurrentSong);
            Play();
        }
Пример #2
0
        public void Play()
        {
            if (State == PlayState.Playing)
            {
                Stop();
            }

            if (_playThread == null)
            {
                _playThread = new Thread(new ThreadStart(ProgressThread));
            }

            if (State == PlayState.Paused)
            {
                Pause();
            }
            else if (PlayQueue.Count > 0)
            {
                State = PlayState.Playing;
                if (CurrentSong == null)
                {
                    CurrentSong = PlayQueue.Dequeue();
                    PlayedSongs.Enqueue(CurrentSong);
                }
            }
            else
            {
                //nothing to play
                Stop();
            }

            if (State == PlayState.Playing)
            {
                if (CurrentSong == null)
                {
                    CurrentSong = PlayQueue.Peek();
                }
                if (!CurrentSong.IsPlayable || (!Config.Instance.PlayWavs && CurrentSong.FileType.ToLowerInvariant() == "wav"))
                {
                    Console.ResetColor();
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.Out.WriteLine("cannot play song. skipping.");
                    Console.ResetColor();
                    Skip();
                    return;
                }

                State = PlayState.Playing;
                ConsoleUtils.UOut(ConsoleColor.DarkGreen, "downloading...");
                //todo : this should happen in a background thread.
                byte[] songBytes = Subsonic.PreloadSong(CurrentSong.Id);
                _hgcFile = GCHandle.Alloc(songBytes, GCHandleType.Pinned);
                ConsoleUtils.UOut(ConsoleColor.DarkGreen, "download complete.");

                _currentSongChannel = Bass.BASS_StreamCreateFile(_hgcFile.AddrOfPinnedObject(), 0, songBytes.Length, BASSFlag.BASS_SAMPLE_FLOAT);
                Bass.BASS_ChannelPlay(_currentSongChannel, false);

                if (!_playThread.IsAlive)
                {
                    if (_playThread.ThreadState == ThreadState.Running)
                    {
                        _playThread.Join();
                    }
                    _playThread = new Thread(new ThreadStart(ProgressThread));
                    _playThread.Start();
                }
            }
        }
Пример #3
0
 public List <Song> GetPlayedSongs()
 {
     return(PlayedSongs.ToList());
 }