public async Task <List <PlaylistFile> > GetMorePlaylist(CancellationToken token, uint offset) { if (InternetService.Connected) { try { IList <IPlaylistFile> playlistsVk; List <PlaylistFile> playlists = new List <PlaylistFile>(); try { IsLoading = true; Changed("IsLoading"); playlistsVk = await Library.Playlists(20, Playlists.Count); foreach (var playlist in playlistsVk) { playlists.Add(await Services.VKontakte.PlaylistsService.ConvertToPlaylistFile(playlist)); } } catch (Flurl.Http.FlurlHttpException) { IsLoading = false; Changed("IsLoading"); hasMorePlaylists = false; await ContentDialogService.Show(new ErrorConnectContentDialog()); InternetService.GoToOfflineMode(); } if (playlists.Count == 0) { VisibilityNoPlaylists = Visibility.Visible; Changed("VisibilityNoPlaylists"); } if (playlists.Count < 20) { hasMorePlaylists = false; } IsLoading = false; Changed("IsLoading"); return(playlists); }catch (Exception e) { IsLoading = false; Changed("IsLoading"); await ContentDialogService.Show(new ExceptionDialog("Неизвестная ошибка при получении плейлистов", "Мы не смогли получить информацию о Ваших плейлистах", e)); return(new List <PlaylistFile>()); } } else { IsLoading = false; Changed("IsLoading"); InternetService.GoToOfflineMode(); return(new List <PlaylistFile>()); } }
public MainFrameView() { this.InitializeComponent(); Window.Current.SetTitleBar(TitleBar); StaticContent.PlayerMenuFrame = PlayerMenuFrame; StaticContent.NavigationContentService = new Services.NavigationService() { RootFrame = ContentFrame }; PlayerMenuFrame.Navigate(typeof(PlayerMenuView)); PlayerBottomFrame.Navigate(typeof(MiniPlayerView)); if (StaticContent.IsPro) { AdsPanel.Height = new GridLength(0, GridUnitType.Pixel); } else { BottomAdsFrame.Navigate(typeof(AdsBottomPanelView)); } Windows.UI.ViewManagement.ApplicationView appView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView(); appView.SetPreferredMinSize(new Size(600, 800)); this.SizeChanged += MainPage_SizeChanged; var timer2 = new DispatcherTimer(); _timer2 = timer2; timer2.Interval = TimeSpan.FromSeconds(80); timer2.Tick += Timer2_Tick; timer2.Start(); if (!StaticContent.Config.IsRateMe & StaticContent.IsAuth) { var timer = new DispatcherTimer(); this._timer = timer; timer.Interval = TimeSpan.FromSeconds(60); timer.Tick += Timer_Tick; timer.Start(); } if (StaticContent.IsAuth) { if (InternetService.CheckConnection()) { StaticContent.NavigationContentService.Go(typeof(VKontakte.HomeView)); } else { InternetService.GoToOfflineMode(); //StaticContent.NavigationContentService.Go(typeof(HomeLocalView)); } } else { StaticContent.NavigationContentService.Go(typeof(HomeLocalView)); } }
public async Task <List <AudioFile> > GetMoreAudio(CancellationToken token, uint offset) { if (InternetService.Connected) { try { if (firstLoading) { IsLoading = true; Changed("IsLoading"); } IList <IAudioFile> tracks = new List <IAudioFile>(); List <AudioFile> music = new List <AudioFile>(); try { tracks = await Popular.Tracks(20, Tracks.Count); music = await MusicService.ConvertToAudioFile(tracks); } catch (Flurl.Http.FlurlHttpException) { music = new List <AudioFile>(); hasMoreLoading = false; await ContentDialogService.Show(new ErrorConnectContentDialog()); InternetService.GoToOfflineMode(); } if (music.Count < 20) { hasMoreLoading = false; } firstLoading = false; IsLoading = false; Changed("IsLoading"); return(music); }catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Неизвестная ошибка при получении списка популярного", "Мы не смогли получить нужную нам информацию о треках", e)); return(new List <AudioFile>()); } } else { hasMoreLoading = false; InternetService.GoToOfflineMode(); return(new List <AudioFile>()); } }
public async Task LoadingInfo() { try { var user = await Fooxboy.MusicX.Core.VKontakte.Users.Info.CurrentUser(); NameUser = $"{user.FirstName} {user.LastName}"; ImageUser = await ImagesService.AvatarUser(user.PhotoUser); Changed("NameUser"); Changed("ImageUser"); }catch (Flurl.Http.FlurlHttpException) { await ContentDialogService.Show(new ErrorConnectContentDialog()); InternetService.GoToOfflineMode(); }catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Невозможно получить информацию о вашем аккаунте", "", e)); } }
public async static Task PlayMusic(AudioFile audioFile, int typePlay, PlaylistFile playlistPlay = null) { if (StaticContent.Config.StreamMusic) { await MusicX.Core.VKontakte.Music.Library.StreamToStatus(audioFile.Id, audioFile.OwnerId); } try { //type play: //1 - проигрования из списка треков //2 - проигрование трека из плейлиста StaticContent.AudioService.Seek(TimeSpan.Zero); var playlistNowPlay = new PlaylistFile() { Artist = "Music X", Cover = "ms-appx:///Assets/Images/now.png", Id = 1000, Name = "Сейчас играет", TracksFiles = new List <AudioFile>(), IsLocal = false }; if (typePlay == 1) { foreach (var trackMusic in StaticContent.MusicVKontakte) { playlistNowPlay.TracksFiles.Add(trackMusic); } var index = playlistNowPlay.TracksFiles.IndexOf(playlistNowPlay.TracksFiles.Single(t => t.Id == audioFile.Id)); if (index != 0) { StaticContent.AudioService.SetCurrentPlaylist(playlistNowPlay.ToAudioPlaylist(), false); StaticContent.AudioService.CurrentPlaylist.CurrentItem = audioFile; } else { StaticContent.AudioService.SetCurrentPlaylist(playlistNowPlay.ToAudioPlaylist(), true); StaticContent.AudioService.SwitchNext(); } StaticContent.NowPlayPlaylist = playlistNowPlay; } else if (typePlay == 2) { StaticContent.NowPlayPlaylist = playlistPlay; playlistNowPlay.TracksFiles = playlistPlay.TracksFiles; playlistNowPlay.Tracks = playlistPlay.Tracks; var index = playlistPlay.TracksFiles.IndexOf(playlistPlay.TracksFiles.Single(t => t.Id == audioFile.Id)); if (index != 0) { StaticContent.AudioService.SetCurrentPlaylist(playlistPlay.ToAudioPlaylist(), false); StaticContent.AudioService.CurrentPlaylist.CurrentItem = audioFile; } else { StaticContent.AudioService.SetCurrentPlaylist(playlistPlay.ToAudioPlaylist(), true); StaticContent.AudioService.SwitchNext(); } } if (!(StaticContent.PlaylistsVKontakte.Any(p => p.Id == 1000))) { StaticContent.PlaylistsVKontakte.Insert(0, playlistNowPlay); } }catch (Flurl.Http.FlurlHttpException) { InternetService.GoToOfflineMode(); } catch (HttpRequestException) { InternetService.GoToOfflineMode(); }catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Ошибка при воспроизведении трека", "Произошла неизвестная ошибка.", e)); } }
public TrackControl() { this.InitializeComponent(); PlayCommand = new RelayCommand(async() => { if (Track.IsLocal) { await PlayMusicService.PlayMusicForLibrary(Track, 1); } else { await MusicService.PlayMusic(Track, 1); } }); DeleteCommand = new RelayCommand(async() => { try { if (Track.IsLocal) { StaticContent.Music.Remove(Track); AudioFile trackByPlaylist = null; if (Track.PlaylistId != 0) { var playlist = await Services.PlaylistsService.GetById(Track.PlaylistId); trackByPlaylist = playlist.TracksFiles.Single(t => t.SourceString == Track.SourceString); playlist.TracksFiles.Remove(trackByPlaylist); await Services.PlaylistsService.SavePlaylist(playlist); } if (trackByPlaylist != null) { if (trackByPlaylist.Source == null) { trackByPlaylist.Source = await StorageFile.GetFileFromPathAsync(Track.SourceString); } await trackByPlaylist.Source.DeleteAsync(); } else { if (Track.Source == null) { Track.Source = await StorageFile.GetFileFromPathAsync(Track.SourceString); } await Track.Source.DeleteAsync(); } await MusicFilesService.UpdateMusicCollection(); } else { //TODO: удаление трека ебаный врот } }catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Невозможно удалить этот трек", "Возможно, этот трек был уже удален.", e)); } }); AddToFavoriteCommand = new RelayCommand(async() => { try { if (Track.IsLocal) { var playlist = await Services.PlaylistsService.GetById(2); if (playlist.TracksFiles.Any(t => t.SourceString == Track.SourceString)) { var dialog = new MessageDialog("Данный трек уже добавлен в избранное", "Ошибка при добавлении в избранное"); await dialog.ShowAsync(); } else { Like.Visibility = Visibility.Collapsed; LikeAdd.Visibility = Visibility.Visible; Track.IsFavorite = true; playlist.TracksFiles.Add(Track); await Services.PlaylistsService.SavePlaylist(playlist); } } else { } }catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Невозможно добавить трек в избранное", "Возможно, этот трек поврежден или не существует плейлиста, если ошибка будет повторяться, переустановите приложение.", e)); } }); RemoveFavoriteCommand = new RelayCommand(() => { }); AddOnLibraryCommand = new RelayCommand(async() => { try { await Fooxboy.MusicX.Core.VKontakte.Music.Add.ToLibrary(Track.Id, Track.AccessKey); await new MessageDialog("Трек добавлен в Вашу библиотеку").ShowAsync(); }catch (Flurl.Http.FlurlHttpException) { InternetService.GoToOfflineMode(); } catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Ошибка при добавлении трека", "Возникла ошибка при добавлении трека в Вашу библиотеку", e)); } }); GetPropertyCommand = new RelayCommand(async() => { await ContentDialogService.Show(new PropertiesTrackContentDialog(Track)); }); GoToArtistCommand = new RelayCommand(() => { StaticContent.NavigationContentService.Go(typeof(ArtistView), new ArtistParameter() { Id = Track.ArtistId, Name = Track.Artist }); }); }