public void Play() { if (!_isLocked && Songs.Count > 0) { _isPlaying = true; } if (_isPlaying) { foreach (var song in Songs) { song.Playing = true; SongStartedEvent?.Invoke(this); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer()) { player.SoundLocation = song.Path; player.PlaySync(); } song.Playing = false; } } _isPlaying = false; }
//public Player(ISkin skin) : base(skin) //{ //} public override Task <bool> Play(bool loop) { return(Task.Run(() => { if (!Locked && Items.Count > 0) { Playing = true; PlayerStartedEvent?.Invoke(Items, null, Locked, Volume, Playing); } if (Playing) { int numLoop = 0; numLoop = (loop == false) ? 1 : 5; //Skin.NewScreen(); for (int j = 0; j < numLoop; j++) { foreach (var item in Items) { try { ViewPlayList(item); SongStartedEvent?.Invoke(Items, item, Locked, Volume, Playing); soundPlayer.SoundLocation = item.Path; soundPlayer.PlaySync(); //soundPlayer.Play(); } catch (FileNotFoundException) { OnWarning?.Invoke("Файл не найден"); throw new FailedToPlayException("Файл не найден", item.Path); } catch (InvalidOperationException) { OnWarning?.Invoke("Проверте расширение файла"); throw new System.Exception("Проверте расширение файла"); } Console.ResetColor(); } } Playing = false; System.Threading.Thread.Sleep(2000); } return Playing; })); //else Skin.Render("Player is Locked"); }
public async Task Play(List <Song> song)//LA8.Player1/2. AsyncPlaySong { foreach (var item in song) { SongStartedEvent?.Invoke(song); if (token.IsCancellationRequested)//установка токена отмены { break; } _sp = new System.Media.SoundPlayer(item.Path); Program.SkinForRef.Render(item.Title); await Task.Run(() => _sp.Load()); await Task.Run(() => _sp.PlaySync()); } }
//public void Play(bool loop = false) //{ // var playCount = loop ? Songs.Count : 1; // if (_isLocked) // { // return; // } // _isPlaying = true; // for (int i = 0; i < playCount; i++) // { // Console.WriteLine($"Player is playing: {Songs[i].Name}, duration: {Songs[i].Duration}"); // System.Threading.Thread.Sleep(1000); // } //} public void Play(bool loop = false) { if (_isLocked) { return; } ISkin.NewScreen(); var playCount = loop ? Songs.Count : 1; for (int i = 0; i < playCount; i++) { if (Songs[i].Like.GetValueOrDefault(false)) { //Console.ForegroundColor = ConsoleColor.Green; //Console.WriteLine($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); //Console.ResetColor(); ISkin.Render($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); foreach (var song in Songs) { PlayingSong = song; SongStartedEvent?.Invoke(Songs, song, _isLocked, _volume); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer()) { player.SoundLocation = PlayingSong.Path; player.PlaySync(); } } } // else if (Songs[i].Like.HasValue ? !Songs[i].Like.Value : false) else if (Songs[i].Like.HasValue && !Songs[i].Like.Value) { //Console.ForegroundColor = ConsoleColor.Red; //Console.WriteLine($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); //Console.ResetColor(); ISkin.Render($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); foreach (var song in Songs) { PlayingSong = song; SongStartedEvent?.Invoke(Songs, song, _isLocked, _volume); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer()) { player.SoundLocation = PlayingSong.Path; player.PlaySync(); } } } else { //Console.WriteLine($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); ISkin.Render($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); System.Threading.Thread.Sleep(1000); foreach (var song in Songs) { PlayingSong = song; SongStartedEvent?.Invoke(Songs, song, _isLocked, _volume); using (System.Media.SoundPlayer player = new System.Media.SoundPlayer()) { player.SoundLocation = PlayingSong.Path; player.PlaySync(); } } } //Console.WriteLine($"Player is playing: {Songs[i].Name}, duration: {Songs[i].Duration}"); //Skin.Render($"Player is playing liked songs: {Songs[i].Name}, duration: {Songs[i].Duration}"); //System.Threading.Thread.Sleep(1000); } }