diff --git a/MyNCMusic/Helper/LoginHelper.cs b/MyNCMusic/Helper/LoginHelper.cs index a5c7df9..34b3093 100644 --- a/MyNCMusic/Helper/LoginHelper.cs +++ b/MyNCMusic/Helper/LoginHelper.cs @@ -50,7 +50,7 @@ public static LoginRoot LoginAccount() static LoginStatus GetLoginStatus() { string result = Http.Get(ConfigService.ApiUri + "/login/status"); - return JsonConvert.DeserializeObject(result); + return result==null?null:JsonConvert.DeserializeObject(result); } } } diff --git a/MyNCMusic/MainPage.xaml b/MyNCMusic/MainPage.xaml index b6db72e..705c3d9 100644 --- a/MyNCMusic/MainPage.xaml +++ b/MyNCMusic/MainPage.xaml @@ -25,7 +25,8 @@ + Margin="0,-1,0,0" + > @@ -40,7 +41,7 @@ + TintOpacity="0.4"/> diff --git a/MyNCMusic/MainPage.xaml.cs b/MyNCMusic/MainPage.xaml.cs index 3029170..6f6ef4c 100644 --- a/MyNCMusic/MainPage.xaml.cs +++ b/MyNCMusic/MainPage.xaml.cs @@ -72,6 +72,7 @@ public MainPage() _mediaPlayer.MediaEnded += _mediaPlayer_MediaEnded; _mediaPlayer.SourceChanged += _mediaPlayer_SourceChanged; + //接管系统播放音频控制 _mediaPlayer.CommandManager.NextBehavior.EnablingRule = MediaCommandEnablingRule.Always; _mediaPlayer.CommandManager.PreviousBehavior.EnablingRule = MediaCommandEnablingRule.Always; @@ -97,6 +98,8 @@ public MainPage() Window.Current.SetTitleBar(MyTitleBar); } + + private async void PlayingService_OnPlayingRadioChanged() { ChangeImage(); @@ -210,6 +213,7 @@ await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { isSliderChangedFromAuto = true; Slider_play.Value = sender.Position.TotalSeconds; + TextBlock_currentTime.Text = OtherHelper.GetDt((int)sender.Position.TotalSeconds); if ((Application.Current as App).playingPage != null) (Application.Current as App).playingPage.ChangeLyricPosition(sender.Position.TotalMilliseconds); @@ -220,6 +224,7 @@ private async void _mediaPlayer_MediaEnded(MediaPlayer sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { + _mediaTimelineController.Pause(); if (PlayingService.IsPlayingSong) PlayingService.PlayNextSongs(); else @@ -283,8 +288,11 @@ async void GetLastPlayingInfo() UpDatePlayOrderStateIcon(); if (PlayingService.PlayingSongUrlRoot != null) { - _mediaSource = await Task.Run(() => MediaSource.CreateFromUri(new Uri(PlayingService.PlayingSongUrlRoot.data.First().url))); + SongUrlRoot songUrlRoot = SongService.GetMusicUrl(PlayingService.PlayingSongUrlRoot.data.First().id); + //_mediaSource = await Task.Run(() => MediaSource.CreateFromUri(new Uri(PlayingService.PlayingSongUrlRoot.data.First().url))); + _mediaSource = await Task.Run(() => MediaSource.CreateFromUri(new Uri(songUrlRoot.data.First().url))); _mediaSource.OpenOperationCompleted += _mediaSource_OpenOperationCompleted; + _mediaSource.StateChanged += _mediaSource_StateChanged; _mediaPlaybackItem = new MediaPlaybackItem(_mediaSource); _mediaPlayer.Source = _mediaPlaybackItem; @@ -293,6 +301,11 @@ async void GetLastPlayingInfo() } } + private void _mediaSource_StateChanged(MediaSource sender, MediaSourceStateChangedEventArgs args) + { + + } + /// /// 启动时获取应用设置 @@ -310,7 +323,7 @@ void GetSetting() private async void _mediaSource_OpenOperationCompleted(MediaSource sender, MediaSourceOpenOperationCompletedEventArgs args) { _duration = sender.Duration.GetValueOrDefault(); - + //_mediaTimelineController.Duration = _duration; await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { Slider_play.Maximum = _duration.TotalSeconds; diff --git a/MyNCMusic/MyNCMusic.csproj b/MyNCMusic/MyNCMusic.csproj index 11c1215..63ab038 100644 --- a/MyNCMusic/MyNCMusic.csproj +++ b/MyNCMusic/MyNCMusic.csproj @@ -199,6 +199,9 @@ Recommendation.xaml + + SettingPage.xaml + @@ -316,6 +319,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + diff --git a/MyNCMusic/Services/ConfigService.cs b/MyNCMusic/Services/ConfigService.cs index a4972e3..7eb26ac 100644 --- a/MyNCMusic/Services/ConfigService.cs +++ b/MyNCMusic/Services/ConfigService.cs @@ -1,6 +1,7 @@ using MyNCMusic.Helper; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Net; using System.Text; @@ -11,6 +12,7 @@ namespace MyNCMusic.Services { [Serializable] + [Bindable(true)] public class ConfigService { public static StorageFolder Folder = ApplicationData.Current.LocalFolder; diff --git a/MyNCMusic/Services/PlayingService .cs b/MyNCMusic/Services/PlayingService .cs index 9397e2d..7f88c4b 100644 --- a/MyNCMusic/Services/PlayingService .cs +++ b/MyNCMusic/Services/PlayingService .cs @@ -1,5 +1,6 @@ using MyNCMusic.Helper; using MyNCMusic.Model; +using MyNCMusic.MyUserControl; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -189,8 +190,17 @@ public static async Task ChangePlayingSong(long playingSongId, List ChangePlayingSong(long playingSongId, SongsItem songsItem = null) @@ -483,7 +493,12 @@ public static async void PlayNextSongs() return; } } - await PlayingService.ChangePlayingSong(willPlayId, PlayingService.PlayingSongList); + for (int i = 0; i < 5; i++) + { + if (await ChangePlayingSong(willPlayId, PlayingSongList)) + break; + } + NotifyPopup notifyPopup = new NotifyPopup("多次获取音乐失败,停止播放"); } /// @@ -494,7 +509,12 @@ public static async void PlayLastSongs() if (PlayedSongId!=null&&PlayedSongId.Count > 1)//上一个是当前歌曲,所以要上上一个 { PlayedSongId.Remove(PlayedSongId.Last());//移出当前 - await PlayingService.ChangePlayingSong(PlayedSongId.Last(), PlayingService.PlayedSongList); + for (int i = 0; i < 5; i++) + { + if (await ChangePlayingSong(PlayedSongId.Last(), PlayingService.PlayedSongList)) + break; + } + NotifyPopup notifyPopup = new NotifyPopup("多次获取音乐失败,停止播放"); } } @@ -555,7 +575,12 @@ public static async void PlayNextRadio() return; } } - await ChangePlayingRadio(willPlayId, PlayingRadioList); + for (int i = 0; i < 5; i++) + { + if (await ChangePlayingRadio(willPlayId, PlayingRadioList)) + break; + } + NotifyPopup notifyPopup = new NotifyPopup("多次获取音乐失败,停止播放"); } /// @@ -566,7 +591,12 @@ public static async void PlayLastRadio() if (PlayedRadioId!=null&&PlayedRadioId.Count > 1)//上一个是当前电台,所以要上上一个 { PlayedRadioId.Remove(PlayedRadioId.Last());//移出当前 - await ChangePlayingRadio(PlayedRadioId.Last(), PlayedRadioList); + for (int i = 0; i < 5; i++) + { + if (await ChangePlayingRadio(PlayedRadioId.Last(), PlayedRadioList)) + break; + } + NotifyPopup notifyPopup = new NotifyPopup("多次获取音乐失败,停止播放"); } } diff --git a/MyNCMusic/Views/Home.xaml.cs b/MyNCMusic/Views/Home.xaml.cs index fea1b7a..47e67ac 100644 --- a/MyNCMusic/Views/Home.xaml.cs +++ b/MyNCMusic/Views/Home.xaml.cs @@ -19,6 +19,7 @@ using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Media.Animation; using Windows.UI.Xaml.Navigation; // https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板 @@ -48,7 +49,7 @@ private async void Home_Loaded(object sender, RoutedEventArgs e) if (!isFirstTimeLoad) return; isFirstTimeLoad = false; - AcrylicBrush_mainFrame.TintColor = MainPage.backgroundBrush.Color;//acrylic背景颜色 + //AcrylicBrush_mainFrame.TintColor = MainPage.backgroundBrush.Color;//acrylic背景颜色 TextBox_account.Text = ConfigService.PhoneOrEmail; PasswordBox_password.Password = ConfigService.Password; TextBox_serverIP.Text = ConfigService.ApiUri.ToString(); @@ -133,9 +134,10 @@ private void Button_myCollection_Click(object sender, RoutedEventArgs e) } } - private async void Button_setting_Click(object sender, RoutedEventArgs e) + private void Button_setting_Click(object sender, RoutedEventArgs e) { - await ContentDialog_setting.ShowAsync(); + //await ContentDialog_setting.ShowAsync(); + Frame_main.Navigate(typeof(SettingPage),null, new DrillInNavigationTransitionInfo()); } private async void ContentDialog_setting_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) diff --git a/MyNCMusic/Views/MyMusicList.xaml b/MyNCMusic/Views/MyMusicList.xaml index 722da0f..e5a1afd 100644 --- a/MyNCMusic/Views/MyMusicList.xaml +++ b/MyNCMusic/Views/MyMusicList.xaml @@ -42,12 +42,17 @@ + CornerRadius="4"> - + + + @@ -68,12 +73,17 @@ + CornerRadius="4"> - + + + diff --git a/MyNCMusic/Views/MyMusicList.xaml.cs b/MyNCMusic/Views/MyMusicList.xaml.cs index 68c8146..09e6c34 100644 --- a/MyNCMusic/Views/MyMusicList.xaml.cs +++ b/MyNCMusic/Views/MyMusicList.xaml.cs @@ -1,4 +1,5 @@ using MyNCMusic.Model; +using MyNCMusic.MyUserControl; using MyNCMusic.Services; using System; using System.Collections.Generic; @@ -42,6 +43,12 @@ private async void MyMusicList_Loaded(object sender, RoutedEventArgs e) playlistItems_created = new ObservableCollection(); playlistItems_subscribed = new ObservableCollection(); MyPlaylistRoot myPlaylistRoot = await Task.Run(() => PlaylistService.GetMyPlaylist()); + if(myPlaylistRoot==null|| myPlaylistRoot.playlist==null) + { + NotifyPopup notifyPopup = new NotifyPopup("获取失败"); + notifyPopup.Show(); + return; + } foreach (var temp in myPlaylistRoot.playlist) { if (temp.subscribed == "true") diff --git a/MyNCMusic/Views/PlayListDetai.xaml.cs b/MyNCMusic/Views/PlayListDetai.xaml.cs index 3ae503d..e41becf 100644 --- a/MyNCMusic/Views/PlayListDetai.xaml.cs +++ b/MyNCMusic/Views/PlayListDetai.xaml.cs @@ -125,8 +125,8 @@ private void AutoSuggestBox_search_TextChanged(AutoSuggestBox sender, AutoSugges ListBox_musicDetail.ItemsSource = musicDetailRootSource.songs; else { - var list = musicDetailRootSource.songs.Where(p => p.Name.Contains(sender.Text)) as System.Collections.ObjectModel.ObservableCollection; - if (list != null && list.Count != 0) + var list = musicDetailRootSource.songs.Where(p => p.Name.Contains(sender.Text)); + if (list != null && list.Count() != 0) { ListBox_musicDetail.ItemsSource = list; } diff --git a/MyNCMusic/Views/PlayingPage.xaml b/MyNCMusic/Views/PlayingPage.xaml index a4837c2..4ffceb0 100644 --- a/MyNCMusic/Views/PlayingPage.xaml +++ b/MyNCMusic/Views/PlayingPage.xaml @@ -136,7 +136,8 @@ + Grid.Column="0" + /> diff --git a/MyNCMusic/Views/Recommendation.xaml b/MyNCMusic/Views/Recommendation.xaml index 4623c46..2e6b44c 100644 --- a/MyNCMusic/Views/Recommendation.xaml +++ b/MyNCMusic/Views/Recommendation.xaml @@ -54,12 +54,18 @@ + CornerRadius="4"> - + + + + @@ -288,6 +294,7 @@ + @@ -297,7 +304,10 @@ Style="{StaticResource AutoSuggestBoxStyle1}" QuerySubmitted="AutoSuggestBox_search_QuerySubmitted" /> - + @@ -488,12 +498,17 @@ + CornerRadius="4"> - + + + diff --git a/MyNCMusic/Views/Recommendation.xaml.cs b/MyNCMusic/Views/Recommendation.xaml.cs index d24e6a7..7d5669d 100644 --- a/MyNCMusic/Views/Recommendation.xaml.cs +++ b/MyNCMusic/Views/Recommendation.xaml.cs @@ -263,42 +263,45 @@ private void AutoSuggestBox_search_QuerySubmitted(AutoSuggestBox sender, AutoSug async void IntoSearch(string keyword) { + ProgressBar_Searching.Visibility = Visibility.Visible; searchType = int.Parse(((PivotItem)Pivot_search.SelectedItem).Tag.ToString()); SearchRoot searchRoot = await Task.Run(() => SearchService.SearchClound(keyword, searchType)); - if (searchRoot == null) - return; - switch (searchType) + if (searchRoot != null&& searchRoot.result!=null) { - case 1: - { - //判断是否为喜欢歌曲 - if (MainPage.favoriteSongsRoot != null) + switch (searchType) + { + case 1: { - foreach (var temp in searchRoot.result.songs) + //判断是否为喜欢歌曲 + if (MainPage.favoriteSongsRoot != null) { - if (MainPage.favoriteSongsRoot.ids.Find(p => p.Equals(temp.Id)) != 0) - temp.isFavorite = true; + foreach (var temp in searchRoot.result.songs) + { + if (MainPage.favoriteSongsRoot.ids.Find(p => p.Equals(temp.Id)) != 0) + temp.isFavorite = true; + } } + ListBox_searchSong.ItemsSource = searchRoot.result.songs; } - ListBox_searchSong.ItemsSource = searchRoot.result.songs; - } - break; - case 10: - { - ListBox_searchAlbum.ItemsSource = searchRoot.result.albums; - } - break; - case 100: - { - ListBox_searchArtist.ItemsSource = searchRoot.result.artists; - } - break; - case 1000: - { - AdaptiveGridView_searchPlaylist.ItemsSource = searchRoot.result.playlists; - } - break; + break; + case 10: + { + ListBox_searchAlbum.ItemsSource = searchRoot.result.albums; + } + break; + case 100: + { + ListBox_searchArtist.ItemsSource = searchRoot.result.artists; + } + break; + case 1000: + { + AdaptiveGridView_searchPlaylist.ItemsSource = searchRoot.result.playlists; + } + break; + } } + ProgressBar_Searching.Visibility = Visibility.Collapsed; } private async void ListBox_searchSong_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) @@ -375,6 +378,8 @@ List prepareToNavigeteToPlaylitDetail(long id) private void Pivot_search_SelectionChanged(object sender, SelectionChangedEventArgs e) { + if (string.IsNullOrEmpty(AutoSuggestBox_search.Text)) + return; string keyword = AutoSuggestBox_search.Text; IntoSearch(keyword); } diff --git a/MyNCMusic/Views/SettingPage.xaml b/MyNCMusic/Views/SettingPage.xaml new file mode 100644 index 0000000..23a163d --- /dev/null +++ b/MyNCMusic/Views/SettingPage.xaml @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +