コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: justplus/doubanFM1
 /// <summary>
 /// 异步获取歌曲列表
 /// </summary>
 /// <param name="type"></param>
 /// <param name="queryKeywrod"></param>
 private async void getSongs(int type, string queryKeywrod)
 {
     if (queryKeywrod != string.Empty)
     {
         string cate = string.Empty;
         int limit = 175;
         if (type == 0)
             cate = "misc";
         else if (type == 1)
             cate = "name";
         else if (type == 2)
             cate = "album";
         else
             cate = "singer";
         string url = string.Format("http://douban.fm/j/open_channel/creation/search?keyword={0}&cate={1}&limit={2}", queryKeywrod, cate, limit);
         SearchSongResult ssr = new SearchSongResult();
         tipSongLabel.Content = "加载中...";
         await Task.Run(() =>
         {
             string jsonresults = new ConnectionBase().Get(url);
             ssr = SearchSongResult.FromJson(jsonresults);
         });
         if (ssr != null && ssr.status)
         {
             tipSongLabel.Content = "";
             foreach (SimpleSong simpleSong in ssr.data.songs)
             {
                 DefSongInfo defSongInfo = new DefSongInfo(simpleSong);
                 defSongInfo.playButton.MouseLeftButtonDown += delegate
                 {
                     player.Pause();
                     playerPlay.Source = new BitmapImage(new Uri("Images/Play.png", UriKind.RelativeOrAbsolute));
                     player.Tag = "Play";
                     if (!defSongInfo.IsPlaying)
                     {
                         searchplayer.Source = new Uri(defSongInfo.SimpleSongInfo.url, UriKind.Absolute);
                         searchplayer.Play();
                         defSongInfo.IsPlaying = true;
                         defSongInfo.playButton.Source = new BitmapImage(new Uri("Images/Pause.png", UriKind.RelativeOrAbsolute));
                     }
                     else
                     {
                         searchplayer.Pause();
                         defSongInfo.IsPlaying = false;
                         defSongInfo.playButton.Source = new BitmapImage(new Uri("Images/Play.png", UriKind.RelativeOrAbsolute));
                     }
                 };
                 SongsQueryed.Children.Add(defSongInfo);
             }
         }
         else
             tipSongLabel.Content = "加载失败...";
     }
 }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: justplus/doubanFM1
        /// <summary>
        /// 异步获取歌曲列表
        /// </summary>
        /// <param name="type"></param>
        /// <param name="queryKeywrod"></param>
        private async void getSongs(int type, string queryKeywrod)
        {
            if (queryKeywrod != string.Empty)
            {
                string cate  = string.Empty;
                int    limit = 175;
                if (type == 0)
                {
                    cate = "misc";
                }
                else if (type == 1)
                {
                    cate = "name";
                }
                else if (type == 2)
                {
                    cate = "album";
                }
                else
                {
                    cate = "singer";
                }
                string           url = string.Format("http://douban.fm/j/open_channel/creation/search?keyword={0}&cate={1}&limit={2}", queryKeywrod, cate, limit);
                SearchSongResult ssr = new SearchSongResult();
                tipSongLabel.Content = "加载中...";
                await Task.Run(() =>
                {
                    string jsonresults = new ConnectionBase().Get(url);
                    ssr = SearchSongResult.FromJson(jsonresults);
                });

                if (ssr != null && ssr.status)
                {
                    tipSongLabel.Content = "";
                    foreach (SimpleSong simpleSong in ssr.data.songs)
                    {
                        DefSongInfo defSongInfo = new DefSongInfo(simpleSong);
                        defSongInfo.playButton.MouseLeftButtonDown += delegate
                        {
                            player.Pause();
                            playerPlay.Source = new BitmapImage(new Uri("Images/Play.png", UriKind.RelativeOrAbsolute));
                            player.Tag        = "Play";
                            if (!defSongInfo.IsPlaying)
                            {
                                searchplayer.Source = new Uri(defSongInfo.SimpleSongInfo.url, UriKind.Absolute);
                                searchplayer.Play();
                                defSongInfo.IsPlaying         = true;
                                defSongInfo.playButton.Source = new BitmapImage(new Uri("Images/Pause.png", UriKind.RelativeOrAbsolute));
                            }
                            else
                            {
                                searchplayer.Pause();
                                defSongInfo.IsPlaying         = false;
                                defSongInfo.playButton.Source = new BitmapImage(new Uri("Images/Play.png", UriKind.RelativeOrAbsolute));
                            }
                        };
                        SongsQueryed.Children.Add(defSongInfo);
                    }
                }
                else
                {
                    tipSongLabel.Content = "加载失败...";
                }
            }
        }