Beispiel #1
0
        private async void PlayerService_TrackChanged(IPlayerService sender, TrackChangedEventArgs e)
        {
            _currentTrackId = e.TrackID;
            if (Tracks == null)
            {
                return;
            }

            if (_currentTrackId >= 0)
            {
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (CurrentTrack != null)
                    {
                        CurrentTrack.IsCurrent = false;
                    }

                    CurrentTrack           = Tracks[_currentTrackId];
                    CurrentTrack.IsCurrent = true;

                    _position = TimeSpan.Zero;
                    OnPropertyChanged(nameof(Position));

                    Duration = TimeSpan.FromSeconds(1);

                    TrackChanged?.Invoke(this, CurrentTrack);
                    ShowLyricsCommand.RaiseCanExecuteChanged();
                    DownloadTrackCommand.RaiseCanExecuteChanged();
                });

                LoadArtistImage(CurrentTrack.Track);
                LoadTrackImage(CurrentTrack.Track);
            }
        }
Beispiel #2
0
        private async void LoadPlayerState()
        {
            _appLoaderService.Show();
            RepeatMode     = _playerService.RepeatMode;
            _isShuffleMode = _playerService.IsShuffleMode;
            OnPropertyChanged(nameof(IsShuffleMode));

            _isScrobbleMode = _playerService.IsScrobbleMode;
            OnPropertyChanged(nameof(IsScrobbleMode));

            IsPlaying       = _playerService.CurrentState == PlayerState.Playing;
            _currentTrackId = _playerService.CurrentTrackID;

            Duration = _playerService.Duration;

            _position = _playerService.Position;
            OnPropertyChanged(nameof(Position));

            IEnumerable <IPlayerTrack> loadedPlaylist = null;

            if (IsShuffleMode)
            {
                loadedPlaylist = await _playerPlaylistService.ReadShuffledPlaylist();
            }
            else
            {
                loadedPlaylist = await _playerPlaylistService.ReadPlaylist();
            }

            if (loadedPlaylist == null)
            {
                await Task.Delay(1);

                _navigationService.Navigate("NoTracksView", null);
                _navigationService.RemoveLastPage("PlayerView");
                _appLoaderService.Hide();
                return;
            }
            else
            {
                _tracks = loadedPlaylist.ToList();
            }

            Tracks = new ObservableCollection <PlayerItem>(_tracks.Select(t => new PlayerItem {
                Track = t
            }));

            if (_currentTrackId >= 0)
            {
                CurrentTrack           = Tracks[_currentTrackId];
                CurrentTrack.IsCurrent = true;

                LoadArtistImage(CurrentTrack.Track);
                LoadTrackImage(CurrentTrack.Track);
                ShowLyricsCommand.RaiseCanExecuteChanged();
                DownloadTrackCommand.RaiseCanExecuteChanged();
            }

            CanShuffle = true;
            _appLoaderService.Hide();
            UpdateAppBarState(CurrentPivotIndex);

            TryShowLikeInfo();
        }