示例#1
0
 public void Refresh(PlaybackContext playback)
 {
     if (playback?.HasError() == false && playback.Item?.HasError() == false &&
         playback.ProgressMs != currentTime)
     {
         TrackTimeChanged?.Invoke(new TrackTimeInfo((uint)playback.ProgressMs, (uint)playback.Item.DurationMs));
         currentTime = playback.ProgressMs;
     }
 }
示例#2
0
            private void DoTick()
            {
                _previousContext = _currentContext;
                try
                {
                    _currentContext = _api.GetPlayback();
                }
                catch (SpotifyWebApiException ex)
                {
                    MessageBox.Show(ex.Message);
                    Thread.Sleep(5000);
                    return;
                }

                try
                {
                    if (_currentContext == null)
                    {
                        return;
                    }

                    // Check volume change
                    if (CompareContext(c => c.Device?.VolumePercent, out var oldVolume, out var newVolume))
                    {
                        // Volume Changed
                        VolumeChanged?.Invoke(this,
                                              new VolumeChangeEventArgs(oldVolume.GetValueOrDefault(),
                                                                        newVolume.GetValueOrDefault()));
                    }

                    if (CompareContext(c => c.Item, out var oldTrack, out var newTrack))
                    {
                        // Track Changed
                        TrackChanged?.Invoke(this, new TrackChangeEventArgs(oldTrack, newTrack));
                    }

                    if (CompareContext(c => c.IsPlaying))
                    {
                        // Playstate Changed
                        PlayStateChanged?.Invoke(this, new PlayStateChangeEventArgs(_currentContext.IsPlaying));
                    }

                    if (CompareContext(c => c.ProgressMs, out var oldProgressMs, out var newProgressMs))
                    {
                        // Track Time Changed
                        TrackTimeChanged?.Invoke(this,
                                                 new TrackTimeChangeEventArgs(TimeSpan
                                                                              .FromMilliseconds(newProgressMs)));
                    }

                    Tick?.Invoke(this, new EventArgs());
                }
                catch { }
            }
示例#3
0
        private void RegisterNotifiers()
        {
            TrackTimeNotifier ttn = new TrackTimeNotifier(_api);

            ttn.TrackTimeChanged += t => TrackTimeChanged?.Invoke(t);

            SongChangedNotifier scn = new SongChangedNotifier(_api);

            scn.TrackChanged += s => TrackChanged?.Invoke(s);

            notifiers.Add(ttn);
            notifiers.Add(scn);
        }
示例#4
0
    protected override void OnTrackTimeChanged(TrackTimeChanged e)
    {
        base.OnTrackTimeChanged(e);

        if (m_playingSlider != null)
        {
            //Dont update when dragging slider
            if (m_isDraggingTrackPositionSlider)
            {
                return;
            }

            m_playingSlider.value    = e.CurrentPositionMs;
            m_playingSlider.maxValue = e.TotalTimeMs;
        }

        if (m_trackPositionText != null)
        {
            SetTrackPositionText(e.CurrentPositionMs, e.TotalTimeMs);
        }
    }
示例#5
0
    protected override void OnTrackTimeChanged(TrackTimeChanged e)
    {
        base.OnTrackTimeChanged(e);

        if (m_playingSlider != null)
        {
            //Dont update when dragging slider
            if (m_isDraggingTrackPositionSlider)
            {
                return;
            }

            m_playingSlider.value    = e.CurrentPosition;
            m_playingSlider.maxValue = e.TotalTime;
        }

        if (m_trackPositionText != null)
        {
            string currentPosFormat = e.CurrentPositionSpan.ToString(@"mm\:ss");
            string totalTimeFormat  = e.TotalTimeSpan.ToString(@"mm\:ss");
            m_trackPositionText.text = $"{currentPosFormat}/{totalTimeFormat}";
        }
    }
 protected virtual void OnTrackTimeChanged(TrackTimeChanged e)
 {
 }