Merge pull request #70 from JimmyAppelt/events

Events
This commit is contained in:
Jonas Dellinger 2016-01-22 23:15:19 +01:00
commit 507cf4dda7
2 changed files with 12 additions and 20 deletions

View File

@ -102,23 +102,23 @@ namespace SpotifyAPI.Example
isPlayingLabel.Text = playing.ToString(); isPlayingLabel.Text = playing.ToString();
} }
private void _spotify_OnVolumeChange(VolumeChangeEventArgs e) private void _spotify_OnVolumeChange(object sender, VolumeChangeEventArgs e)
{ {
volumeLabel.Text = (e.NewVolume * 100).ToString(CultureInfo.InvariantCulture); volumeLabel.Text = (e.NewVolume * 100).ToString(CultureInfo.InvariantCulture);
} }
private void _spotify_OnTrackTimeChange(TrackTimeChangeEventArgs e) private void _spotify_OnTrackTimeChange(object sender, TrackTimeChangeEventArgs e)
{ {
timeLabel.Text = $"{FormatTime(e.TrackTime)}/{FormatTime(_currentTrack.Length)}"; timeLabel.Text = $"{FormatTime(e.TrackTime)}/{FormatTime(_currentTrack.Length)}";
timeProgressBar.Value = (int)e.TrackTime; timeProgressBar.Value = (int)e.TrackTime;
} }
private void _spotify_OnTrackChange(TrackChangeEventArgs e) private void _spotify_OnTrackChange(object sender, TrackChangeEventArgs e)
{ {
UpdateTrack(e.NewTrack); UpdateTrack(e.NewTrack);
} }
private void _spotify_OnPlayStateChange(PlayStateEventArgs e) private void _spotify_OnPlayStateChange(object sender, PlayStateEventArgs e)
{ {
UpdatePlayingStatus(e.Playing); UpdatePlayingStatus(e.Playing);
} }

View File

@ -52,21 +52,13 @@ namespace SpotifyAPI.Local
private readonly Timer _eventTimer; private readonly Timer _eventTimer;
private StatusResponse _eventStatusResponse; private StatusResponse _eventStatusResponse;
public delegate void TrackChangeEventHandler(TrackChangeEventArgs e); public event EventHandler<TrackChangeEventArgs> OnTrackChange;
public delegate void PlayStateEventHandler(PlayStateEventArgs e); public event EventHandler<PlayStateEventArgs> OnPlayStateChange;
public delegate void VolumeChangeEventHandler(VolumeChangeEventArgs e); public event EventHandler<VolumeChangeEventArgs> OnVolumeChange;
public delegate void TrackTimeChangeEventHandler(TrackTimeChangeEventArgs e); public event EventHandler<TrackTimeChangeEventArgs> OnTrackTimeChange;
public event TrackChangeEventHandler OnTrackChange;
public event PlayStateEventHandler OnPlayStateChange;
public event VolumeChangeEventHandler OnVolumeChange;
public event TrackTimeChangeEventHandler OnTrackTimeChange;
public SpotifyLocalAPI() public SpotifyLocalAPI()
{ {
@ -104,7 +96,7 @@ namespace SpotifyAPI.Local
{ {
if (newStatusResponse.Track.TrackResource?.Name != _eventStatusResponse.Track.TrackResource?.Name) if (newStatusResponse.Track.TrackResource?.Name != _eventStatusResponse.Track.TrackResource?.Name)
{ {
OnTrackChange?.Invoke(new TrackChangeEventArgs() OnTrackChange?.Invoke(this, new TrackChangeEventArgs()
{ {
OldTrack = _eventStatusResponse.Track, OldTrack = _eventStatusResponse.Track,
NewTrack = newStatusResponse.Track NewTrack = newStatusResponse.Track
@ -113,14 +105,14 @@ namespace SpotifyAPI.Local
} }
if (newStatusResponse.Playing != _eventStatusResponse.Playing) if (newStatusResponse.Playing != _eventStatusResponse.Playing)
{ {
OnPlayStateChange?.Invoke(new PlayStateEventArgs() OnPlayStateChange?.Invoke(this, new PlayStateEventArgs()
{ {
Playing = newStatusResponse.Playing Playing = newStatusResponse.Playing
}); });
} }
if (newStatusResponse.Volume != _eventStatusResponse.Volume) if (newStatusResponse.Volume != _eventStatusResponse.Volume)
{ {
OnVolumeChange?.Invoke(new VolumeChangeEventArgs() OnVolumeChange?.Invoke(this, new VolumeChangeEventArgs()
{ {
OldVolume = _eventStatusResponse.Volume, OldVolume = _eventStatusResponse.Volume,
NewVolume = newStatusResponse.Volume NewVolume = newStatusResponse.Volume
@ -128,7 +120,7 @@ namespace SpotifyAPI.Local
} }
if (newStatusResponse.PlayingPosition != _eventStatusResponse.PlayingPosition) if (newStatusResponse.PlayingPosition != _eventStatusResponse.PlayingPosition)
{ {
OnTrackTimeChange?.Invoke(new TrackTimeChangeEventArgs() OnTrackTimeChange?.Invoke(this, new TrackTimeChangeEventArgs()
{ {
TrackTime = newStatusResponse.PlayingPosition TrackTime = newStatusResponse.PlayingPosition
}); });