标签:play tps margin utf-8 搜索数据 function 中文 script on()
搜索歌曲
function go() {
var val = document.getElementById("name").value;
let url = ‘https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp?g_tk=5381&uin=0&format=jsonp&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=h5&needNewCode=1&w=‘+val+‘&zhidaqu=1&catZhida=1&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1&remoteplace=txt.mqq.all&_=1520833663464‘;
$.ajax({
url:url,
type:"get",
dataType:‘jsonp‘,
jsonp: "callback",
jsonpCallback:‘callback‘,
scriptCharset: ‘GBK‘,//解决中文乱码
success: function(data){
//获取搜索数据
var myul = document.getElementById(‘myul‘);
var songs = data.data.song.list;
// var a =""
/* alert(data.data.song.list.length); */
$("ul").find("li").remove();
for(var i=0;i<songs.length;i++){
var songmid = songs[i].songmid;
var songname = songs[i].songname;
var singername = songs[i].singer[0].name;
var albummid = songs[i].albummid;
$("#myul").append(‘<li ><a id=‘+i+‘ class=‘+albummid+‘ data=‘+songmid +‘ style="font-size:15px;" >‘+songname+‘---‘+singername+"</a></li>");
}
$(‘a‘).on(‘click‘,function(){ //绑定事件
//获取播放器
var myAudio = document.getElementById(‘myaudio‘);
var myimg = document.getElementById(‘myimg‘);
//获取url
var href= $(this).attr(‘data‘);
var src =$(this).attr(‘class‘);
//给播放器添加url
myAudio.src=‘http://ws.stream.qqmusic.qq.com/C100‘+href+‘.m4a?fromtag=0‘;
myimg.src=‘//y.gtimg.cn/music/photo_new/T002R300x300M000‘+src+‘.jpg‘;
//播放音乐
myAudio.play();
});
},
error:function (e) {
console.log(‘error‘);
Indicator.close();
}
});
}
播放歌曲
let url = ‘http://ws.stream.qqmusic.qq.com/C100‘+songmid+‘.m4a?fromtag=0
歌曲图片
//y.gtimg.cn/music/photo_new/T002R300x300M000+albummid+.jpg
标签:play tps margin utf-8 搜索数据 function 中文 script on()
原文地址:https://www.cnblogs.com/chenlove/p/8796991.html