Example #1
0
            public async Task <Model.Player.NowPlay> GetNowPlay()
            {
                var music = new Class.Model.Player.NowPlay();

                if (moredata.filename.Contains("-"))
                {
                    var spits = moredata.filename.Split('-');
                    music.title      = spits[1].Replace(" ", "");
                    music.singername = spits[0].Replace(" ", "");
                    var singer = await GetSingerResult(music.singername);

                    if (singer == null)
                    {
                        music.imgurl = "ms-appx:///Assets/image/songimg.png";
                    }
                    else
                    {
                        music.imgurl = singer.imgurl;
                    }
                }
                else
                {
                    music.title      = moredata.filename;
                    music.singername = "未知歌手";
                    music.imgurl     = "ms-appx:///Assets/image/songimg.png";
                }
                music.url = await GetUrl();

                music.hash    = hash;
                music.albumid = "";
                return(music);
            }
                public async Task <Class.Model.Player.NowPlay> GetNowPlay()
                {
                    var music = new Class.Model.Player.NowPlay();

                    music.title = filename;
                    music.url   = await GetUrl();

                    if (album_id != "0" && album_id != "")
                    {
                        music.albumid = album_id;
                    }
                    if (singername.Length > 0)
                    {
                        music.singername = singername;
                        var singer = await Class.Model.SearchResultModel.GetSingerResult(singername);

                        if (singer == null)
                        {
                            music.imgurl = "ms-appx:///Assets/image/songimg.png";
                        }
                        else
                        {
                            music.imgurl = singer.imgurl;
                        }
                    }
                    else
                    {
                        music.singername = "未知歌手";
                        music.imgurl     = "ms-appx:///Assets/image/songimg.png";
                    }
                    return(music);
                }
 private async void LocalList_Selecyion(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         LoadProgress.IsActive = true;
         var list = sender as ListView;
         if (list.SelectedIndex != -1)
         {
             if (list.SelectedItem != null)
             {
                 var data    = list.SelectedItem as Music;
                 var nowplay = new Class.Model.Player.NowPlay();
                 if (data.path == null && data.path == "")
                 {
                     LoadProgress.IsActive = false;
                     return;
                 }
                 nowplay.url        = data.path;
                 nowplay.title      = data.Title;
                 nowplay.singername = data.songer;
                 nowplay.albumid    = "";
                 nowplay.imgurl     = "ms-appx:///Assets/image/songimg.png";
                 await Class.Model.PlayList.Add(nowplay, true);
             }
             list.SelectedIndex = -1;
         }
         LoadProgress.IsActive = false;
     }
     catch (Exception)
     {
     }
 }
 private async void init()
 {
     mainFrame = Window.Current.Content as Frame;
     BackgroundMedia = Class.MediaControl.GetCurrent();
     BackgroundMedia.CurrentStateChanged += BackgroundMedia_CurrentStateChanged;
     ProcessTimer.Interval = TimeSpan.FromMilliseconds(1000);
     ProcessTimer.Tick += ProcessTimer_Tick;
     nowplay = await Class.Model.PlayList.GetNowPlay();
     if(nowplay!=null)
     {
         SongName_Text.Text = nowplay.title;
         SingerName_Text.Text = nowplay.singername;
         Singer_Image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri(nowplay.imgurl) };
     }
     else
     {
         SongName_Text.Text = "酷狗音乐";
         SingerName_Text.Text = "传播好音乐";
         Singer_Image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri("ms-appx:///Assets/image/songimg.png") };
     }
     if(BackgroundMedia.CurrentState==MediaPlayerState.Playing)
     {
         Play_Btn_Icon.Symbol = Symbol.Pause;
         ProcessTimer.Start();
     }
     else
     {
         Play_Btn_Icon.Symbol = Symbol.Play;
     }
     //ProcessTimer.Start();
 }
        private async void ToolBtnClicked(object sender, RoutedEventArgs e)
        {
            var btn = sender as AppBarButton;

            switch (btn.TabIndex)
            {
            case 0:
                await new Windows.UI.Popups.MessageDialog("正在建设").ShowAsync();
                break;

            case 1:
                if (nowplay != null && nowplay.url.Contains("http://") && nowplay.hash != null && nowplay.hash != "")
                {
                    DataTransferManager.ShowShareUI();
                }
                else
                {
                    await new Windows.UI.Popups.MessageDialog("本地歌曲无法分享").ShowAsync();
                }
                break;

            case 2:
                LoadProgress.Visibility = Visibility.Visible;
                nowplay = await Class.Model.Player.GetNowPlay();

                if (nowplay.url != null && nowplay.url.Contains("http://"))
                {
                    await KG_ClassLibrary.BackgroundDownload.Start(nowplay.singername + "-" + nowplay.title, nowplay.url, KG_ClassLibrary.BackgroundDownload.DownloadType.song);

                    await new Windows.UI.Popups.MessageDialog(ResourceLoader.GetForCurrentView().GetString("AddDownSuccess")).ShowAsync();
                }
                else
                {
                    await new Windows.UI.Popups.MessageDialog(ResourceLoader.GetForCurrentView().GetString("DownLocalFalied") + nowplay.url).ShowAsync();
                }
                LoadProgress.Visibility = Visibility.Collapsed;
                break;

            case 3:
                if (nowplay != null)
                {
                    if (nowplay.singername == null || nowplay.singername == "未知歌手" || nowplay.singername == "传播好音乐")
                    {
                        MoreToolBtn2.Visibility = Visibility.Collapsed;
                    }
                    if (singerdata == null || singerdata.pics == null)
                    {
                        MoreToolBtn3.Visibility = Visibility.Collapsed;
                    }
                    MoreToolBtnBar.IsOpen = true;
                }
                break;

            default:
                break;
            }
        }
        private void BackgroundMedia_CurrentStateChanged(MediaPlayer sender, object args)
        {
            var state = sender.CurrentState;

            mainFrame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                switch (state)
                {
                case MediaPlayerState.Closed:
                    Play_Btn_Icon.Symbol = Symbol.Play;
                    ProcessTimer.Stop();
                    break;

                case MediaPlayerState.Opening:
                    Play_Btn_Icon.Symbol = Symbol.Pause;
                    break;

                case MediaPlayerState.Buffering:
                    Song_Progress.IsIndeterminate = true;
                    break;

                case MediaPlayerState.Playing:
                    Play_Btn_Icon.Symbol = Symbol.Pause;
                    ProcessTimer.Start();
                    Song_Progress.IsIndeterminate = false;
                    nowplay              = await Class.Model.Player.GetNowPlay();
                    SongName_Text.Text   = nowplay.title;
                    SingerName_Text.Text = nowplay.singername;
                    Singer_Image.Source  = new Windows.UI.Xaml.Media.Imaging.BitmapImage()
                    {
                        UriSource = new Uri(nowplay.imgurl)
                    };
                    break;

                case MediaPlayerState.Paused:
                    Play_Btn_Icon.Symbol = Symbol.Play;
                    ProcessTimer.Stop();
                    break;

                case MediaPlayerState.Stopped:
                    Play_Btn_Icon.Symbol = Symbol.Play;
                    ProcessTimer.Stop();
                    break;

                default:
                    break;
                }
            });
        }
        private async void ProcessTimer_Tick(object sender, object e)
        {
            Song_Progress.Maximum = BackgroundMedia.NaturalDuration.TotalSeconds;;
            Song_Progress.Value   = BackgroundMedia.Position.TotalSeconds;
            if (nowplay == null)
            {
                nowplay = await Class.Model.Player.GetNowPlay();

                SongName_Text.Text   = nowplay.title;
                SingerName_Text.Text = nowplay.singername;
                Singer_Image.Source  = new Windows.UI.Xaml.Media.Imaging.BitmapImage()
                {
                    UriSource = new Uri(nowplay.imgurl)
                };
            }
        }
        private async void init()
        {
            mainFrame       = Window.Current.Content as Frame;
            BackgroundMedia = Class.MediaControl.GetCurrent();
            BackgroundMedia.CurrentStateChanged += BackgroundMedia_CurrentStateChanged;
            ProcessTimer.Interval = TimeSpan.FromMilliseconds(1000);
            ProcessTimer.Tick    += ProcessTimer_Tick;
            nowplay = await Class.Model.PlayList.GetNowPlay();

            if (nowplay != null)
            {
                SongName_Text.Text   = nowplay.title;
                SingerName_Text.Text = nowplay.singername;
                Singer_Image.Source  = new Windows.UI.Xaml.Media.Imaging.BitmapImage()
                {
                    UriSource = new Uri(nowplay.imgurl)
                };
            }
            else
            {
                SongName_Text.Text   = "酷狗音乐";
                SingerName_Text.Text = "传播好音乐";
                Singer_Image.Source  = new Windows.UI.Xaml.Media.Imaging.BitmapImage()
                {
                    UriSource = new Uri("ms-appx:///Assets/image/songimg.png")
                };
            }
            if (BackgroundMedia.CurrentState == MediaPlayerState.Playing)
            {
                Play_Btn_Icon.Symbol = Symbol.Pause;
                ProcessTimer.Start();
            }
            else
            {
                Play_Btn_Icon.Symbol = Symbol.Play;
            }
            //ProcessTimer.Start();
        }
 private async void MusicList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     LoadProess.IsActive = false;
     var list = sender as ListView;
     var song = list.SelectedItem as MusicData;
     string url = "";
     string hash = "";
     if (song.hash_sq != "")
     {
         url = await kugou.get_song_url(song.hash_sq);
         hash = song.hash_sq;
     }
     else
     {
         if (song.hash_320 != "")
         {
             url = await kugou.get_song_url(song.hash_320);
             hash = song.hash_320;
         }
         else
         {
             if (song.hash != "")
             {
                 url = await kugou.get_song_url(song.hash);
                 hash = song.hash;
             }
         }
     }
     if (url!=null&&url != "")
     {
         var music = new Class.Model.Player.NowPlay();
         var filename = song.moredata.filename;
         if (filename.Contains("-"))
         {
             var spits = filename.Split('-');
             music.title = spits[1].Replace(" ", "");
             music.singername = spits[0].Replace(" ", "");
             var singer = await GetSingerResult(music.singername);
             if (singer == null)
             {
                 music.imgurl = "ms-appx:///Assets/image/songimg.png";
             }
             else
             {
                 music.imgurl = singer.imgurl;
             }
         }
         else
         {
             music.title = song.moredata.filename;
             music.singername = "未知歌手";
             music.imgurl = "ms-appx:///Assets/image/songimg.png";
         }
         music.url = url;
         music.hash = hash;
         music.albumid = "";
         await Class.Model.Player.SetNowPlay(music);
         Class.Model.PlayList.Add(music, true);
     }
     else
     {
         await new MessageDialog("该音乐暂时无法播放!").ShowAsync();
     }
     LoadProess.IsActive = false;
 }
 private void BackgroundMedia_CurrentStateChanged(MediaPlayer sender, object args)
 {
     var state = sender.CurrentState;
     mainFrame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
      {
          switch (state)
          {
              case MediaPlayerState.Closed:
                  Play_Btn_Icon.Symbol = Symbol.Play;
                  ProcessTimer.Stop();
                  break;
              case MediaPlayerState.Opening:
                  Play_Btn_Icon.Symbol = Symbol.Pause;
                  break;
              case MediaPlayerState.Buffering:
                  Song_Progress.IsIndeterminate = true;
                  break;
              case MediaPlayerState.Playing:
                  Play_Btn_Icon.Symbol = Symbol.Pause;
                  ProcessTimer.Start();
                  Song_Progress.IsIndeterminate = false;
                  nowplay = await Class.Model.Player.GetNowPlay();
                  SongName_Text.Text = nowplay.title;
                  SingerName_Text.Text = nowplay.singername;
                  Singer_Image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri(nowplay.imgurl) };
                  break;
              case MediaPlayerState.Paused:
                  Play_Btn_Icon.Symbol = Symbol.Play;
                  ProcessTimer.Stop();
                  break;
              case MediaPlayerState.Stopped:
                  Play_Btn_Icon.Symbol = Symbol.Play;
                  ProcessTimer.Stop();
                  break;
              default:
                  break;
          }
      });
 }
 private async void ProcessTimer_Tick(object sender, object e)
 {
     Song_Progress.Maximum = BackgroundMedia.NaturalDuration.TotalSeconds; ;
     Song_Progress.Value = BackgroundMedia.Position.TotalSeconds;
     if (nowplay == null)
     {
         nowplay = await Class.Model.Player.GetNowPlay();
         SongName_Text.Text = nowplay.title;
         SingerName_Text.Text = nowplay.singername;
         Singer_Image.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri(nowplay.imgurl) };
     }
 }
        private async void init()
        {
            BackgroundMedia       = Class.MediaControl.GetCurrent();
            ProcessTimer.Interval = TimeSpan.FromMilliseconds(800);
            PicTimer.Interval     = TimeSpan.FromSeconds(60);
            PicTimer.Tick        += async(s, e) =>
            {
                if (PlayerFlip.SelectedIndex == 1)
                {
                    if (singerdata != null && singerdata.pics != null && singerdata.pics.Count > 0)
                    {
                        if (picnum == singerdata.pics.Count - 1)
                        {
                            picnum = 0;
                        }
                        else
                        {
                            picnum = picnum + 1;
                        }
                        if (PlayerFlip.SelectedIndex == 1)
                        {
                            WriteableBitmap wb = new WriteableBitmap(1000, 1500);
                            HttpClient      hc = new HttpClient();
                            byte[]          b  = await hc.GetByteArrayAsync(singerdata.pics[picnum].Replace("{size}", "480"));

                            using (IRandomAccessStream iras = b.AsBuffer().AsStream().AsRandomAccessStream())
                            {
                                await wb.SetSourceAsync(iras);
                            }
                            BlurEffect be = new BlurEffect(wb);
                            mainGrid.Background = new ImageBrush()
                            {
                                ImageSource = await be.ApplyFilter(1), Stretch = Stretch.UniformToFill
                            };
                        }
                    }
                }
            };
            ProcessTimer.Tick += async(s, e) =>
            {
                ishander = false;
                var alltime    = BackgroundMedia.NaturalDuration.TotalSeconds;
                var alltime_m  = Math.Floor(alltime / 60);
                var alltime_s  = Math.Floor(alltime % 60);
                var thistime   = BackgroundMedia.Position.TotalSeconds;
                var thistime_m = Math.Floor(thistime / 60);
                var thistime_s = Math.Floor(thistime % 60);
                if (alltime_s < 10)
                {
                    AllTime_Text.Text = alltime_m.ToString() + ":0" + alltime_s.ToString();
                }
                else
                {
                    AllTime_Text.Text = alltime_m.ToString() + ":" + alltime_s.ToString();
                };
                if (thistime_s < 10)
                {
                    ThisTime_Text.Text = thistime_m.ToString() + ":0" + thistime_s.ToString();
                }
                else
                {
                    ThisTime_Text.Text = thistime_m.ToString() + ":" + thistime_s.ToString();
                };
                SongSlider.Maximum = alltime;
                SongSlider.Value   = thistime;
                await Task.Delay(50);

                ishander = true;
            };
            lrcpanel.LrcNowText = NowLrc_Text;
            UpdateData();
            if (BackgroundMedia.CurrentState == MediaPlayerState.Playing)
            {
                PlayBtn.Icon = new SymbolIcon(Symbol.Pause);
                nowplay      = await Class.Model.PlayList.GetNowPlay();

                if (nowplay != null)
                {
                    lrcpanel.LrcNowText = NowLrc_Text;
                    lrcpanel.LoadLrcFromLocal();
                }
                ProcessTimer.Start();
            }
            else
            {
                PlayBtn.Icon = new SymbolIcon(Symbol.Play);
            }
            BackgroundMedia.CurrentStateChanged += BackgroundMedia_CurrentStateChanged;
        }
        public async void UpdateData()
        {
            nowplay = await Class.Model.Player.GetNowPlay();

            var playlist = await Class.Model.PlayList.GetPlayList();

            if (playlist != null)
            {
                switch (playlist.cyc)
                {
                case Class.Model.PlayList.cycling.单曲循环:
                    Cyc_Btn.Icon = new SymbolIcon(Symbol.RepeatOne);
                    break;

                case Class.Model.PlayList.cycling.列表循环:
                    Cyc_Btn.Icon = new SymbolIcon(Symbol.RepeatAll);
                    break;

                case Class.Model.PlayList.cycling.随机播放:
                    Cyc_Btn.Icon = new SymbolIcon(Symbol.Shuffle);
                    break;

                default:
                    break;
                }
            }
            NowLrc_Text.Text = "";
            if (nowplay != null)
            {
                SongName_Text.Text   = nowplay.title;
                SingerName_Text.Text = nowplay.singername;

                if (nowplay.albumid.Length > 0)
                {
                    var imgurl = await GetAlbumImg(nowplay.albumid);

                    Album_Img.Source = new BitmapImage(new Uri(imgurl));
                    WriteableBitmap wb = new WriteableBitmap(1000, 1500);
                    HttpClient      hc = new HttpClient();
                    byte[]          b  = await hc.GetByteArrayAsync(imgurl);

                    using (IRandomAccessStream iras = b.AsBuffer().AsStream().AsRandomAccessStream())
                    {
                        await wb.SetSourceAsync(iras);
                    }
                    BlurEffect be = new BlurEffect(wb);
                    albumimgbrush = new ImageBrush()
                    {
                        ImageSource = await be.ApplyFilter(2), Stretch = Stretch.UniformToFill
                    };
                    mainGrid.Background = new ImageBrush()
                    {
                        ImageSource = await be.ApplyFilter(2), Stretch = Stretch.UniformToFill
                    };
                }
                else
                {
                    Album_Img.Source = new BitmapImage()
                    {
                        UriSource = new Uri("ms-appx:///Assets/image/albumimg2.png")
                    };
                }
            }
            else
            {
                SongName_Text.Text   = "酷狗音乐";
                SingerName_Text.Text = "传播好音乐";
            }
        }
 private async void init()
 {
     BackgroundMedia = Class.MediaControl.GetCurrent();
     ProcessTimer.Interval = TimeSpan.FromSeconds(60);
     PicTimer.Interval = TimeSpan.FromSeconds(15);
     PicTimer.Tick += (s, e) =>
    {
        if(PlayerFlip.SelectedIndex==1)
        {
            if (singerdata != null && singerdata.pics != null && singerdata.pics.Count > 0)
            {
                if (picnum == singerdata.pics.Count - 1)
                {
                    picnum = 0;
                }
                else
                {
                    picnum = picnum + 1;
                }
                mainGrid.Background = new ImageBrush() { ImageSource = new Windows.UI.Xaml.Media.Imaging.BitmapImage() { UriSource = new Uri(singerdata.pics[picnum].Replace("{size}", "480")) }, Stretch = Stretch.UniformToFill };
            }
        }
    };
     ProcessTimer.Tick += async (s, e) =>
     {
         ishander = false;
         var alltime = BackgroundMedia.NaturalDuration.TotalSeconds;
         var alltime_m = Math.Floor(alltime / 60);
         var alltime_s = Math.Floor(alltime % 60);
         var thistime = BackgroundMedia.Position.TotalSeconds;
         var thistime_m = Math.Floor(thistime / 60);
         var thistime_s = Math.Floor(thistime % 60);
         if (alltime_s < 10)
         {
             AllTime_Text.Text = alltime_m.ToString() + ":0" + alltime_s.ToString();
         }
         else
         {
             AllTime_Text.Text = alltime_m.ToString() + ":" + alltime_s.ToString();
         };
         if (thistime_s < 10)
         {
             ThisTime_Text.Text = thistime_m.ToString() + ":0" + thistime_s.ToString();
         }
         else
         {
             ThisTime_Text.Text = thistime_m.ToString() + ":" + thistime_s.ToString();
         };
         SongSlider.Maximum = alltime;
         SongSlider.Value = thistime;
         await Task.Delay(50);
         ishander = true;
     };
     lrcpanel.LrcNowText = NowLrc_Text;
     UpdateData();
     if (BackgroundMedia.CurrentState == MediaPlayerState.Playing)
     {
         PlayBtn.Icon = new SymbolIcon(Symbol.Pause);
         nowplay = await Class.Model.PlayList.GetNowPlay();
         if (nowplay != null)
         {
             lrcpanel.LrcNowText = NowLrc_Text;
             lrcpanel.LoadLrcFromLocal();
         }
         ProcessTimer.Start();
     }
     else
     {
         PlayBtn.Icon = new SymbolIcon(Symbol.Play);
     }
     BackgroundMedia.CurrentStateChanged += BackgroundMedia_CurrentStateChanged;
 }
 private async void ListSelection_Changes(object sender, SelectionChangedEventArgs e)
 {
     var thispage = ResultView.SelectedIndex;
     switch (thispage)
     {
         case 0:
             if(SongResultList.SelectionMode==ListViewSelectionMode.Single)
             {
                 SongLoadProgress.IsActive = true;
                 var obj = sender as ListView;
                 if (obj.SelectedItem != null)
                 {
                     var song = obj.SelectedItem as Model.SearchResultModel.Song;
                     string url = "";
                     if (song.sqhash != "")
                     {
                         url = await kugou.get_song_url(song.sqhash);
                     }
                     else
                     {
                         if (song.hash320 != "")
                         {
                             url = await kugou.get_song_url(song.hash320);
                         }
                         else
                         {
                             if (song.hash != "")
                             {
                                 url = await kugou.get_song_url(song.hash);
                             }
                         }
                     }
                     if (url!=null&&url != "")
                     {
                         var music = new Class.Model.Player.NowPlay();
                         music.title = song.filename;
                         music.url = url;
                         music.albumid = song.album_id;
                         if (song.singername.Length > 0)
                         {
                             music.singername = song.singername;
                             var singer = await GetSingerResult(song.singername);
                             if (singer == null)
                             {
                                 music.imgurl = "ms-appx:///Assets/image/songimg.png";
                             }
                             else
                             {
                                 music.imgurl = singer.imgurl;
                             }
                         }
                         else
                         {
                             music.singername = "未知歌手";
                             music.imgurl = "ms-appx:///Assets/image/songimg.png";
                         }
                         await Class.Model.Player.SetNowPlay(music);
                         Class.Model.PlayList.Add(music, true);
                     }
                     else
                     {
                         await new MessageDialog("该音乐暂时无法播放!").ShowAsync();
                     }
                 }
                 SongLoadProgress.IsActive = false;
             }
             break;
         case 1:
             var obj1 = sender as ListView;
             if (obj1.SelectedItem != null)
             {
                 var mv = (Model.SearchResultModel.MV)obj1.SelectedItem;
                 mainframe.Navigate(typeof(page.MVPlayer), mv.hash);
             }
             break;
         case 2:
             var obj2 = sender as GridView;
             if (obj2.SelectedItem != null)
             {
                 var album = (Model.SearchResultModel.Album)obj2.SelectedItem;
                 mainframe.Navigate(typeof(page.AlbumPage), album.albumid);
             }
             break;
         default:
             break;
     }
 }