示例#1
0
        public async Task Run()
        {
            if (Running)
            {
                return;
            }

            await RunSpotifyConnect();

            var isSpotifyPlayingOutsideOfSelectedAudioEndPoint = !SetSpotifyAudioSessionAndWaitToStart();

            BindSpotifyEventHandlers();
            Ready = false;

            if (SpotifyConnect.IsSpotifyRunning())
            {
                _currentTrack = Spotify.GetTrack();
                InitializeRecordingSession();

                while (Running)
                {
                    if (!SpotifyConnect.IsSpotifyRunning())
                    {
                        _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyIsClosed"));
                        Running = false;
                    }
                    else if (_userSettings.HasRecordingTimerEnabled && !_recordingTimer.Enabled)
                    {
                        _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logRecordingTimerDone"));
                        Running = false;
                    }
                    else if (isSpotifyPlayingOutsideOfSelectedAudioEndPoint)
                    {
                        _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyPlayingOutsideOfSelectedAudioEndPoint"));
                        Running = false;
                    }
                    else if (ToggleStopRecordingDelayed)
                    {
                        ToggleStopRecordingDelayed = false;
                        _stopRecordingWhenSongEnds = true;
                        _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logStopRecordingWhenSongEnds"));
                    }
                    Thread.Sleep(200);
                }

                DoIKeepLastSong();
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logStoping"));
            }
            else if (SpotifyConnect.IsSpotifyInstalled())
            {
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyNotConnected"));
            }
            else
            {
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyNotFound"));
            }

            EndRecordingSession();
        }
示例#2
0
        private async Task RunSpotifyConnect()
        {
            if (SpotifyConnect.IsSpotifyInstalled(_fileSystem))
            {
                if (!SpotifyConnect.IsSpotifyRunning())
                {
                    _form.WriteIntoConsole(I18NKeys.LogSpotifyConnecting);
                    await SpotifyConnect.Run(_fileSystem);
                }
            }
            ;

            Running = true;
        }
示例#3
0
        private async Task EnableRecordingTimer()
        {
            _recordingTimer = new Timer(_userSettings.RecordingTimerMilliseconds)
            {
                AutoReset = false,
                Enabled   = false
            };

            while (_recorderTasks.Count == 0 && SpotifyConnect.IsSpotifyRunning())
            {
                await Task.Delay(300);
            }

            _recordingTimer.Enabled = true;
        }
示例#4
0
        private void EnableRecordingTimer()
        {
            _recordingTimer = new Timer(_userSettings.RecordingTimerMilliseconds)
            {
                AutoReset = false,
                Enabled   = false
            };

            while (_recorder == null && SpotifyConnect.IsSpotifyRunning())
            {
                Thread.Sleep(300);
            }

            _recordingTimer.Enabled = true;
        }
示例#5
0
        private async Task RunSpotifyConnect()
        {
            if (!SpotifyConnect.IsSpotifyInstalled())
            {
                return;
            }

            if (!SpotifyConnect.IsSpotifyRunning())
            {
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyConnecting"));
                await SpotifyConnect.Run();
            }

            Running = true;
        }
示例#6
0
        public async Task Run()
        {
            if (Running)
            {
                return;
            }

            Ready   = false;
            Running = true;
            await RunSpotifyConnect();

            if (SpotifyConnect.IsSpotifyRunning())
            {
                InitializeRecordingSession();

                while (Running)
                {
                    if (!SpotifyConnect.IsSpotifyRunning())
                    {
                        _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyIsClosed"));
                        Running = false;
                    }
                    Thread.Sleep(200);
                }

                DoIKeepLastSong();
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logStoping"));
            }
            else if (SpotifyConnect.IsSpotifyInstalled())
            {
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyNotConnected"));
            }
            else
            {
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyNotFound"));
            }

            EndRecordingSession();
        }
示例#7
0
        private async Task RunSpotifyConnect()
        {
            if (SpotifyConnect.IsSpotifyInstalled() && !SpotifyConnect.IsSpotifyRunning())
            {
                _form.WriteIntoConsole(FrmEspionSpotify.Rm.GetString($"logSpotifyConnecting"));
            }

            SpotifyConnect.Run();

            _userSettings.SpotifyAudioSession = new AudioSessions.SpotifyAudioSession();
            await _userSettings.SpotifyAudioSession.WaitSpotifyAudioSessionToStart();

            Spotify = new SpotifyHandler(_userSettings.SpotifyAudioSession)
            {
                ListenForEvents = true
            };
            Spotify.OnPlayStateChange += OnPlayStateChanged;
            Spotify.OnTrackChange     += OnTrackChanged;
            Spotify.OnTrackTimeChange += OnTrackTimeChanged;

            _currentTrack = Spotify.GetTrack();
        }
示例#8
0
        public async Task Run()
        {
            if (Running)
            {
                return;
            }

            _form.WriteIntoConsole(I18NKeys.LogStarting);

            NativeMethods.PreventSleep();

            await RunSpotifyConnect();

            var isAudioSessionNotFound = !await SetSpotifyAudioSessionAndWaitToStart();

            BindSpotifyEventHandlers();
            Ready = false;

            if (Recorder.TestFileWriter(_form, _audioSession, _userSettings))
            {
                if (isAudioSessionNotFound)
                {
                    _form.WriteIntoConsole(I18NKeys.LogSpotifyPlayingOutsideOfSelectedAudioEndPoint);
                    Running = false;
                }
                else if (SpotifyConnect.IsSpotifyRunning())
                {
                    await InitializeRecordingSession();

                    while (Running)
                    {
                        // Order is important
                        if (!SpotifyConnect.IsSpotifyRunning())
                        {
                            _form.WriteIntoConsole(I18NKeys.LogSpotifyIsClosed);
                            Running = false;
                        }
                        else if (ToggleStopRecordingDelayed)
                        {
                            ToggleStopRecordingDelayed = false;
                            _stopRecordingWhenSongEnds = true;
                            _form.WriteIntoConsole(I18NKeys.LogStopRecordingWhenSongEnds);
                        }
                        else if (!_stopRecordingWhenSongEnds && _userSettings.HasRecordingTimerEnabled &&
                                 !_recordingTimer.Enabled)
                        {
                            _form.WriteIntoConsole(I18NKeys.LogRecordingTimerDone);
                            ToggleStopRecordingDelayed = true;
                        }

                        await Task.Delay(WATCHER_DELAY_MS);
                    }

                    DoIKeepLastSong();
                    StopLastRecorder();
                }
                else if (SpotifyConnect.IsSpotifyInstalled(_fileSystem))
                {
                    _form.WriteIntoConsole(isAudioSessionNotFound
                        ? I18NKeys.LogSpotifyIsClosed
                        : I18NKeys.LogSpotifyNotConnected);
                }
                else
                {
                    _form.WriteIntoConsole(I18NKeys.LogSpotifyNotFound);
                }
            }

            EndRecordingSession();

            _form.WriteIntoConsole(I18NKeys.LogStoping);

            NativeMethods.AllowSleep();
        }