コード例 #1
0
        private async void Run()
        {
            try
            {
                _songRequestPlaylistVideoIds = await _youTubeClientInstance.GetPlaylistItemsAsync(_botConfig.YouTubeBroadcasterPlaylistId);

                if (!string.IsNullOrEmpty(_botConfig.YouTubePersonalPlaylistId))
                {
                    if (_botConfig.EnablePersonalPlaylistShuffle)
                    {
                        List <PlaylistItem> shuffledList = await _youTubeClientInstance.GetPlaylistItemsAsync(_botConfig.YouTubePersonalPlaylistId);

                        shuffledList.Shuffle();

                        _personalYoutubePlaylistVideoIds = shuffledList;
                    }
                    else
                    {
                        _personalYoutubePlaylistVideoIds = await _youTubeClientInstance.GetPlaylistItemsAsync(_botConfig.YouTubePersonalPlaylistId);
                    }
                }

                _initialLoadYoutubePlaylist = false;

                SetNextVideoId(); // set current song request playlist item

                if (CurrentSongRequestPlaylistItem == null)
                {
                    _playerStatus = false;
                    return; // don't try to start the VLC video player until there is something to play
                }

                while (true)
                {
                    if (CurrentSongRequestPlaylistItem != null)
                    {
                        await PlayMediaAsync();

                        if (_mediaPlayer?.Media?.State != VLCState.Ended)
                        {
                            _songSkipping = false;
                        }
                    }

                    while (_mediaPlayer?.Media?.State != VLCState.Ended && _playerStatus && !_songSkipping)
                    {
                        // wait
                    }

                    LastPlayedPlaylistItem = CurrentSongRequestPlaylistItem;

                    if (_playerStatus)
                    {
                        SetNextVideoId();
                    }
                    else
                    {
                        break;
                    }
                }

                // Clean up
                _mediaPlayer.Stop();
                _mediaPlayer.Dispose();
                _mediaPlayer = null;
                LibVlc.Dispose();
                LibVlc = null;
            }
            catch (Exception ex)
            {
                await _errHndlrInstance.LogError(ex, "LibVLCSharpPlayer", "Run()", false);
            }
        }