コード例 #1
0
ファイル: SpotifyProcess.cs プロジェクト: jwallet/spy-spotify
        private async Task <(string, bool)> GetSpotifyTitle()
        {
            string mainWindowTitle       = null;
            var    isSpotifyAudioPlaying = false;

            if (_spotifyProcessId.HasValue)
            {
                try
                {
                    isSpotifyAudioPlaying = await _audioSession.IsSpotifyCurrentlyPlaying();

                    var process = _processManager.GetProcessById(_spotifyProcessId.Value);
                    mainWindowTitle = process?.MainWindowTitle ?? "";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {
                _spotifyProcessId = GetSpotifyProcesses(_processManager)
                                    .FirstOrDefault(x => !string.IsNullOrEmpty(x.MainWindowTitle))?.Id;
            }

            return(mainWindowTitle, isSpotifyAudioPlaying);
        }
コード例 #2
0
        private async Task <(string, bool)> GetSpotifyTitle()
        {
            string mainWindowTitle       = null;
            var    isSpotifyAudioPlaying = false;

            if (_spotifyProcessId.HasValue)
            {
                try
                {
                    if (ExternalAPI.Instance.GetTypeAPI == Enums.ExternalAPIType.Spotify && ExternalAPI.Instance.IsAuthenticated)
                    {
                        var(title, isPlaying) = await ExternalAPI.Instance.GetCurrentPlayback();

                        mainWindowTitle       = title;
                        isSpotifyAudioPlaying = isPlaying;
                    }
                    // always fallback if it was not properly set by spotify api
                    if (mainWindowTitle == null)
                    {
                        isSpotifyAudioPlaying = await _audioSession.IsSpotifyCurrentlyPlaying();

                        var process = _processManager.GetProcessById(_spotifyProcessId.Value);
                        mainWindowTitle = process?.MainWindowTitle ?? "";
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            return(mainWindowTitle, isSpotifyAudioPlaying);
        }