示例#1
0
        public void GetSongList(int page)
        {
            DispatchService.Invoke(() =>
            {
                if (string.IsNullOrEmpty(txtSearch.Text))
                {
                    return;
                }


                try
                {
                    var jsonString  = MusicApi.Search(txtSearch.Text, 10, 10 * (page));
                    dynamic jsonObj = JsonConvert.DeserializeObject(jsonString);
                    var result      = jsonObj.result;
                    var songlist    = result.songs;
                    int j           = 1;
                    foreach (var item in songlist)
                    {
                        var album  = item.album;
                        var artist = album.artist;
                        DispatchService.Invoke(() =>
                        {
                            mySongList.Add(new Song
                            {
                                id    = 10 * page + j++,
                                apid  = item.id,
                                title = item.name,
                                path  = @"http://music.163.com/song/media/outer/url?id=" + item.id + ".mp3"
                            });
                        });
                    }
                    //Listview回到顶端
                    if (mySongList.Count > 0)
                    {
                        listViewSongList.ScrollIntoView(listViewSongList.Items[0]);

                        if (!playerInfo.IsShowList)
                        {
                            playerInfo.IsShowList = true;
                        }
                    }
                }
                catch (Exception)
                {
                }
            });
        }
示例#2
0
 public IActionResult Get(string type, string id)
 {
     try
     {
         string json    = MusicApi.Search(id, 1, 0, 1);
         var    jsonObj = JsonConvert.DeserializeObject <dynamic>(json);
         var    result  = jsonObj.result;
         if (result != null)
         {
             var songs = result.songs;
             if (songs != null)
             {
                 string musicId       = songs[0].id;
                 string detailjson    = MusicApi.Detail(musicId);
                 var    detailjsonObj = JsonConvert.DeserializeObject <dynamic>(detailjson);
                 string lyricjson     = MusicApi.Lyric(musicId);
                 var    lyricjsonObj  = JsonConvert.DeserializeObject <dynamic>(lyricjson);
                 string lyric         = string.Empty;
                 if (lyricjsonObj.nolyric == null && lyricjsonObj.uncollected == null)
                 {
                     lyric = lyricjsonObj.lrc.lyric;
                 }
                 var url    = $"http://music.163.com/song/media/outer/url?id={musicId}.mp3";
                 var name   = songs[0].name;
                 var artist = songs[0].artists[0].name;
                 var cover  = detailjsonObj.songs[0].album.picUrl;
                 return(Json(new { code = 0, url = url, name = name, artist = artist, cover = cover, lyric = lyric, msg = "" }));
             }
         }
         return(Json(new { code = 1, msg = "获取音乐链接失败" }));
     }
     catch (Exception ex)
     {
         return(Json(new { code = 1, msg = ex.ToString() }));
     }
 }
示例#3
0
 public HttpResponseMessage Search(string s = null, int limit = 30, int offset = 0, int type = 1)
 {
     return(Json(MusicApi.Search(s, limit, offset, type)));
 }