public AudioListItemModel(VKAudio item) { Contract.Requires(item != null); this.item = item; uriLazy = new Lazy <Uri>(() => new Uri(item.Url)); durationLazy = new Lazy <TimeSpan>(() => TimeSpan.FromSeconds(item.Duration)); }
private async Task Restore() { VKAudio restored = await VKApi.Audio.RestoreAsync(Item.Audio.Id, Item.Audio.OwnerId); if (restored != null) { Item.Audio.Url = restored.Url; Item.Audio.Id = restored.Id; Item.Audio.OwnerId = restored.OwnerId; IsDeleted = false; } }
private async Task AddItemToList(VKAudio item) { var audioWrapper = new AudioListItemModel(item); if (this.currentItem != null && this.currentItem.Item == audioWrapper) { await AddItem(this.currentItem); } else { var itemVM = ServiceLocator.Current.GetInstance <IAudioListItemViewModel>(); itemVM.Item = audioWrapper; await AddItem(itemVM); } }
public LyricsViewModel(VKAudio audio) { Contract.Requires(audio != null); this.audio = audio; }
/// <summary> /// Конструктор по умолчанию. /// </summary> public PlayerViewModel() { #if DEBUG if (IsInDesignModeStatic) { CurrentTrack = new VKAudio { Title = "Poker Face", Artist = "Lady Gaga", LyricsID = 1 }; DurationStart = TimeSpan.FromSeconds(0); DurationEnd = TimeSpan.FromSeconds(123); ArtistImage = new BitmapImage(new Uri("http://userserve-ak.last.fm/serve/500/60890169/Lady+Gaga+Gaga.png")); return; } #endif NextTrack = new RelayCommand(() => { if (Tracks == null || Tracks.Count == 0) { return; } ServiceHelper.PlayerService.NextTrack(); Duration = TimeSpan.Zero; DurationStart = TimeSpan.Zero; DurationEnd = TimeSpan.Zero; if (_currentTrackID + 1 == Tracks.Count) { _currentTrackID = 0; } else { _currentTrackID++; } }); PreviousTrack = new RelayCommand(() => { if (CurrentTrack == null || Tracks == null || Tracks.Count == 0) { return; } ServiceHelper.PlayerService.PreviousTrack(); DurationStart = TimeSpan.Zero; DurationEnd = TimeSpan.Zero; if (_currentTrackID - 1 == -1) { _currentTrackID = Tracks.Count - 1; } else { _currentTrackID--; } }); PlayTrack = new RelayCommand <IAudioTrack>(a => SetNewTrack(a)); PlayResume = new RelayCommand(() => ServiceHelper.PlayerService.ResumePause()); DownloadTrack = new RelayCommand(async() => { var command = new VKSaverDownloadCommand(); //command.Downloads.Add(CoreHelper.GetDownload(CurrentTrack)); await command.TryExecute(); }, () => CurrentTrack != null && !String.IsNullOrEmpty(CurrentTrack.Source)); ShowTrackLyrics = new RelayCommand(() => { NavigationHelper.Navigate(AppViews.TrackLyricsView, CurrentTrack); }, () => CurrentTrack != null && CurrentTrack.LyricsID != 0); _timer.Tick += (s, e) => { if (ServiceHelper.PlayerService.CurrentState == PlayerState.Playing) { try { DurationStart = ServiceHelper.PlayerService.CurrentPosition; DurationEnd = DurationStart - Duration; } catch (Exception) { } } }; _timer.Start(); Messenger.Default.Register <PlayTrackMessage>(this, OnPlayTrackMessageReceived); }