Esempio n. 1
0
        public void UpdateAllPlaylists(bool forceUpdate = false)
        {
            if (!StreamPlayer.IsPlaying && !forceUpdate)
            {
                return;
            }
            PlaybackUpdateQueued = false;
            using (WebClient webClient = new WebClient())
            {
                UpdatePlaylist(webClient, HISTORY_URL, History);
                UpdatePlaylist(webClient, QUEUE_URL, Queue);

                var currentPlayingJSON = webClient.DownloadString(CURRENT_PLAYING_URL);
                var currentPlaying     = JsonConvert.DeserializeObject <CurrentPlaying>(currentPlayingJSON);
                CurrentPlaying.Update(currentPlaying);

                UpdateTimeToCurrentPlaying();
            }
            if (cancellationTokenSource.IsCancellationRequested)
            {
                cancellationTokenSource = new CancellationTokenSource();
            }
            _ = Task.Run(async() =>
            {
                var ms = Convert.ToInt32(CurrentPlaying.PlaybackPositionFromEnd.TotalMilliseconds);
                try
                {
                    await Task.Delay(ms, cancellationTokenSource.Token);
                    await Task.Factory.StartNew(() => { UpdateAllPlaylists(); }, CancellationToken.None, TaskCreationOptions.None, guiDispatcher);
                }
                catch (TaskCanceledException) { }
            });
        }
Esempio n. 2
0
        public void Update(CurrentPlaying currentPlaying)
        {
            var difference = DateTime.Now - currentPlaying.SystemTime;

            SystemTimeDifference = difference + TimeSpan.FromSeconds(OFFSET);

            foreach (var property in GetType().GetProperties())
            {
                if (property.CanWrite)
                {
                    property.SetValue(this, GetType().GetProperty(property.Name).GetValue(currentPlaying));
                }
            }
        }