public async Task <Track> GetTrack() { if (SpotifyLatestStatus == null) { return((await SpotifyProcess.GetSpotifyStatus())?.CurrentTrack); } return(await SpotifyLatestStatus.GetTrack()); }
public Track GetTrack() { if (SpotifyLatestStatus == null) { return(SpotifyProcess.GetSpotifyStatus().Track); } return(SpotifyLatestStatus.GetTrack()); }
public async void ElapsedEventTick(object sender, ElapsedEventArgs e) { SpotifyLatestStatus = await SpotifyProcess.GetSpotifyStatus(); if (SpotifyLatestStatus?.CurrentTrack == null) { EventTimer.Start(); return; } var newestTrack = SpotifyLatestStatus.CurrentTrack; if (Track != null) { if (newestTrack.Playing != Track.Playing) { if (newestTrack.Playing) { SongTimer.Start(); } else { SongTimer.Stop(); } await Task.Run(() => OnPlayStateChange?.Invoke(this, new PlayStateEventArgs() { Playing = newestTrack.Playing })); } if (!newestTrack.Equals(Track)) { SongTimer.Start(); await Task.Run(async() => OnTrackChange?.Invoke(this, new TrackChangeEventArgs() { OldTrack = Track, NewTrack = await SpotifyLatestStatus.GetTrack() })); } if (Track.CurrentPosition != null || newestTrack != null) { await Task.Run(() => OnTrackTimeChange?.Invoke(this, new TrackTimeChangeEventArgs() { TrackTime = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : 0 })); } } if (newestTrack != null) { newestTrack.CurrentPosition = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : (int?)null; Track = newestTrack; } EventTimer.Start(); }
public SpotifyHandler(ISpotifyAudioSession spotifyAudioSession) { SpotifyProcess = new SpotifyProcess(spotifyAudioSession); AttachTimer(_timerInterval); }
public async Task TriggerEvents() { // avoid concurrences if (_processingEvents == true) { return; } _processingEvents = true; SpotifyLatestStatus = await SpotifyProcess.GetSpotifyStatus(); if (SpotifyLatestStatus?.CurrentTrack != null) { var newestTrack = SpotifyLatestStatus.CurrentTrack; if (Track != null) { if (newestTrack.Playing != Track.Playing) { if (newestTrack.Playing) { SongTimer?.Start(); } else { SongTimer?.Stop(); } _ = Task.Run(() => OnPlayStateChange?.Invoke(this, new PlayStateEventArgs() { Playing = newestTrack.Playing })); } if (!newestTrack.Equals(Track)) { SongTimer?.Start(); _ = Task.Run(async() => OnTrackChange?.Invoke(this, new TrackChangeEventArgs() { OldTrack = Track, NewTrack = await SpotifyLatestStatus.GetTrack() })); } if (Track.CurrentPosition != null || newestTrack != null) { _ = Task.Run(() => OnTrackTimeChange?.Invoke(this, new TrackTimeChangeEventArgs() { TrackTime = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : 0 })); } } if (newestTrack != null) { newestTrack.CurrentPosition = newestTrack.Equals(Track) ? Track?.CurrentPosition ?? 0 : (int?)null; Track = newestTrack; } } EventTimerStart(); _processingEvents = false; }
public SpotifyHandler(ISpotifyAudioSession spotifyAudioSession) { SpotifyProcess = new SpotifyProcess(spotifyAudioSession); AttachTimer(TIMER_INTERVAL); }