Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
 }
Beispiel #5
0
    private void StartMove(KeyCode keyCode)
    {
        if (Input.GetKeyDown(keyCode))
        {
            IsMoving = true;
            PlayerStarted?.Invoke();
        }

        if (IsMoving)
        {
            MoveForward(_speed);
            MoveSide(_sideSpeed, _targetLinePosition);
        }
    }
Beispiel #6
0
        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);
        }
Beispiel #7
0
 protected virtual void RaisePlayerStartedEvent(object sender, ProgressEventArgs e) =>
 InvokeActionOnMainThread(() => PlayerStarted?.Invoke(sender, e));