Example #1
0
        private async Task PlayCurrentStream(Stream streamToPlay)
        {
            CurrentStream = streamToPlay;

            // Get ffmepg stream
            var ffmepgProcess = CreateFFmpegStream(CurrentStream.StreamUrl);
            var stream        = ffmepgProcess.StandardOutput.BaseStream;
            var discord       = audioClient.CreatePCMStream(AudioApplication.Music, Configuration.BaseBitrate);

            // Start streaming
            try
            {
                await stream.CopyToAsync(discord, 81920, cancelationToken.Token).ConfigureAwait(false);
            }
            catch (OperationCanceledException e)
            {
            }
            finally
            {
                // Flush buffers / clean
                await discord.FlushAsync().ConfigureAwait(false);

                CurrentStream = null;

                if (!nextStream)
                {
                    PlayerStopped?.Invoke(this);
                }
                else
                {
                    nextStream = false;
                }
            }
        }
Example #2
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);
        }
Example #3
0
        public void CoreMessage(AIMPMessage message, int param1, IntPtr param2, ref IntPtr result)
        {
            switch (message)
            {
            case AIMPMessage.EventPlayableFileInfo:
                FileInfoReceived?.Invoke();
                break;

            case AIMPMessage.EventPlayerState when param1 == 0:
                PlayerStopped?.Invoke();
                break;

            case AIMPMessage.EventLoaded:
                PlayerLoaded?.Invoke();
                break;
            }
        }
Example #4
0
 protected virtual void RaisePlayerStoppedEvent(object sender, EventArgs e) =>
 InvokeActionOnMainThread(() => PlayerStopped?.Invoke(sender, e));
 protected virtual void OnPlayerStopped(EventArgs e)
 {
     PlayerStopped?.Invoke(this, e);
 }