Example #1
0
        public bool Play()
        {
            if (_locked == false && Songs.Count > 0)
            {
                _playing = true;
            }
            PlayerStarted?.Invoke(null, null, _playing, _volume);
            Console.WriteLine("Player has been started");

            if (_playing)
            {
                foreach (var song in Songs)
                {
                    PlayingSong = song;
                    SongStarted?.Invoke(Songs, song, _locked, _volume);
                    using (System.Media.SoundPlayer player = new System.Media.SoundPlayer())
                    {
                        player.SoundLocation = PlayingSong.Path;
                        player.PlaySync();
                    }
                }
            }
            _playing = false;
            return(_playing);
        }
Example #2
0
        private void InternPlaySong(int playlistIndex)
        {
            if (playlistIndex < 0)
            {
                Throw.ArgumentOutOfRangeException(() => playlistIndex, 0);
            }

            if (_currentPlayingPlaylist != null)
            {
                _currentPlayingPlaylist.CurrentSongIndex = null;
            }

            _currentPlayingPlaylist = CurrentPlaylist;

            CurrentPlaylist.CurrentSongIndex = playlistIndex;

            Song song = CurrentPlaylist[playlistIndex].Song;

            RenewCurrentPlayer(song);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    _currentPlayer.Load();
                }

                catch (SongLoadException)
                {
                    //song.IsCorrupted = true;
                    SongCorrupted.RaiseSafe(this, EventArgs.Empty);

                    HandleSongCorruption();

                    return;
                }

                try
                {
                    _currentPlayer.Play();
                }

                catch (PlaybackException)
                {
                    //song.IsCorrupted = true;
                    SongCorrupted.RaiseSafe(this, EventArgs.Empty);

                    HandleSongCorruption();

                    return;
                }

                SongStarted.RaiseSafe(this, EventArgs.Empty);
            });
        }
Example #3
0
 /// <summary>
 /// Raises the <see cref="SongStarted"/> event.
 /// </summary>
 protected void OnSongStarted() =>
 SongStarted?.Invoke(this);
 protected void OnSongStarted()
 {
     SongStarted?
     .Invoke(this, EventArgs.Empty);
 }