private async Task DequeueSong() { // If the player is already playing a song, return if (IsPlaying) { return; } // Check if there are still request on the queue if (songs.Count == 0) { PlayerStopped?.Invoke(this); return; } BaseSong nextSong = songs.Dequeue(); Song songToPlay = null; if (nextSong is YoutubePlaylistSong yps) { songToPlay = await GetSongFromUrl(yps.WebpageUrl); songToPlay.Requester = nextSong.Requester; } else if (nextSong is Song song) { songToPlay = song; } PlayerStarted?.Invoke(this, songToPlay); var _ = PlaySong(songToPlay); }
public void Play(string uri) { if (!IsPrepared) { if (player == null) { player = new MediaPlayer(); player.Prepared += (sender, args) => { player.Start(); IsPrepared = true; PlayerStarted?.Invoke(this, args); }; } else { player.Reset(); } player.SetDataSource(uri); player.PrepareAsync(); } else { player.Start(); PlayerStarted?.Invoke(this, null); } }
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); }
public bool Stop() { if (_locked == false) { _playing = false; } PlayerStarted?.Invoke(null, null, _playing, _volume); Console.WriteLine("Player has been stopped"); return(_playing); }
private void StartMove(KeyCode keyCode) { if (Input.GetKeyDown(keyCode)) { IsMoving = true; PlayerStarted?.Invoke(); } if (IsMoving) { MoveForward(_speed); MoveSide(_sideSpeed, _targetLinePosition); } }
public async Task PlayStream(int id) { // If a stream is already playing if (IsPlaying) { StopStream(true); await Task.Delay(2000); } Stream stream = streams.FirstOrDefault(f => f.Id == id); if (stream == null) { throw new Exception("Stream not found."); } PlayerStarted?.Invoke(this, stream); await PlayCurrentStream(stream); }
protected virtual void RaisePlayerStartedEvent(object sender, ProgressEventArgs e) => InvokeActionOnMainThread(() => PlayerStarted?.Invoke(sender, e));