Example #1
0
        private void OnPlayerEvent(PlayerEventArgs args)
        {
            switch (args.Event)
            {
            case PlayerEvent.StartOfStream:
                // Queue the previous track in case of a skip
                Queue(last_track);

                st.Reset();
                song_start_time   = DateTime.Now;
                last_track        = ServiceManager.PlayerEngine.CurrentTrack;
                queued            = false;
                now_playing_sent  = false;
                iterate_countdown = 4 * 4;      /* we get roughly 4 events/sec */

                break;

            case PlayerEvent.Seek:
                st.SkipPosition();
                break;

            case PlayerEvent.Iterate:
                // Queue as now playing
                if (!now_playing_sent && iterate_countdown == 0)
                {
                    if (last_track != null &&
                        IsValidForSubmission(last_track) &&
                        ((ToggleAction)actions["AudioscrobblerEnableAction"]).Active)
                    {
                        connection.NowPlaying(last_track.ArtistName, last_track.TrackTitle,
                                              last_track.AlbumTitle, last_track.Duration.TotalSeconds, last_track.TrackNumber);
                    }

                    now_playing_sent = true;
                }
                else if (iterate_countdown > 0)
                {
                    iterate_countdown--;
                }

                st.IncreasePosition();
                break;

            case PlayerEvent.EndOfStream:
                Queue(last_track);
                last_track        = null;
                iterate_countdown = 4 * 4;
                break;
            }
        }