Skip to content

Instantly share code, notes, and snippets.

@Hawksbillcat
Created February 23, 2019 03:37
Show Gist options
  • Save Hawksbillcat/775cc09abd1548e04ce5c7b53ac066f6 to your computer and use it in GitHub Desktop.
Save Hawksbillcat/775cc09abd1548e04ce5c7b53ac066f6 to your computer and use it in GitHub Desktop.
public add_list(){ //先爬網頁上的資料
return new Promise((resolve, reject)=>{
this.httpclient.get("URL")
.subscribe(res=>{
if(res["status"]==200){
let qq:string=JSON.parse(JSON.stringify(res))
for(let i=0;i<qq["results"].length;i++){
this.test_three.push({ //這邊是爬網頁上的資料 再PUSH進去
ID:qq["results"][i].ID,
Name:qq["results"][i].Name,
Bitrate:qq["results"][i].Bitrate,
Format:qq["results"][i].Format,
IsAACEnabled:qq["results"][i].IsAACEnabled,
StreamUrl:qq["results"][i].StreamUrl,
IsAddedToLove:false,
active:false
})
}
resolve(this.test_three)
}
else{
reject(this.test_three)
}
})
}).catch(err=>{
console.log("抓歌曲失敗 "+err)
})
}
public playing_song(){
return new Promise((resolve, reject)=>{
let ss:string=this.dp.get_playing_radio();
console.log(" 歌曲網址 "+ss)
for(let u in this.test_three){
if(ss==this.test_three[u].StreamUrl){
let file=JSON.parse(JSON.stringify(this.test_three))
let index=file.map(d=>{
return d["StreamUrl"]
}).indexOf(ss)
console.log("是多少啦~ "+index)
this.test_three[index].active=true;
//resolve(this.test_three[index].active)
resolve(ss)
}
}
// reject(this.test_three[index].active)
})
// .catch(err=>{
// console.log("噁噁噁 沒有歌曲在播"+err)//這邊有沒加入REJECT都沒差
// // return err;
// })
}
public async compair_favorite() {
try {
const [playing_song,add_list] = await Promise.all([
this.playing_song(),//這裡執行失敗也沒差 下面還是會跑
this.add_list()//這裡不受影響
])
}
catch (err) {
console.log('fetch failed', err);
}
}
this.compair_favorite();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment