Compare commits

...

3 Commits

2 changed files with 125 additions and 2 deletions

View File

@ -1,4 +1,21 @@
# WebPlayer
基于网易云音乐 NodeJS 版 API的在线播放器
在线demo: [点此](http://150.158.7.169/player) [新版](http://150.158.7.169/player-nextgen)
在线demo: [点此](http://150.158.7.169/player) [新版](http://150.158.7.169/player-nextgen)
todo:
[] 记忆上次播放,并记忆上次播放列表
[] 单行歌词显示
[] 单独设立播放控制按钮
[] 单独显示播放时间
[] 云播放列表
> 列表ID重复查询
[] 优化业务逻辑数据库存储歌单的时候只存储歌曲ID其余信息在用户端再进行处理
[] 访问网易云音乐歌单或者热歌榜

View File

@ -1,8 +1,37 @@
window.onload = function(){
createlist();
setInterval(checkplay, 3000);
}
// 如果网页失去焦点,则改变标题 -- Writtrn By Copilot
window.onblur = function(){
oldTitle = document.title;
bgplayChecker = setInterval(playstatChecking, 3000);
console.warn("Page checker started");
// if(!document.getElementById("Player").paused){
// changeTitle("playing");
// }else if(nowplaying.songname != "" && nowplaying.artist != ""){
// changeTitle("nowplaying");
// }else{
// //document.title = `[Pause]`;
// }
}
// 如果网页获得焦点,则改变标题 -- Writtrn By Copilot
window.onfocus = function(){
clearInterval(bgplayChecker);
console.warn("Page checker stopped");
changeTitle();
}
nowplaying = {
"songid": "",
"songname": "",
"artist": ""
};
oldTitle = document.title;
var bgplayChecker;
var listPlayChecker;
// 搜索音乐
function getsongs(){
document.getElementById("reslist").innerHTML = "";
@ -60,6 +89,12 @@ function playmusic(playid, songname, artist){
document.getElementById("Player").play();
// 插入到历史记录
inserthistory(playid, songname, artist);
// 更新正在播放的歌曲
nowplaying.songid = playid;
nowplaying.songname = songname;
nowplaying.artist = artist;
// 更新标题
changeTitle(nowplaying);
}
// 队列 -- Writtrn By Copilot & Web
@ -113,6 +148,10 @@ function addlist(songid, songname, artist){
// 播放下一首
function playnext(){
clearInterval(listPlayChecker);
console.warn("Checker Already Cleared. pn")
listPlayChecker = setInterval(checkplay, 3000);
console.warn("Checker Already Set. pn")
if(list.isEmpty()){
console.log("音乐列表已经播放完毕了哦,快加入新的音乐吧~");
alert("音乐列表已经播放完毕了哦,快加入新的音乐吧~");
@ -125,6 +164,7 @@ function playnext(){
// 检测是否播放完毕
function checkplay(){
// 为了防止播放列表结束以后一直调用playnext产生过多的alart所以需要检测播放列表是否为空
console.warn("Checking now play")
if(!list.isEmpty()){
if(document.getElementById("Player").ended){
// 播放完毕后自动播放下一首
@ -132,11 +172,17 @@ function checkplay(){
}
}else{
//clearInterval(checkplay);
clearInterval(listPlayChecker);
console.warn("Checker Already Cleared. cp")
}
}
// 播放列表
function playthelist(){
clearInterval(listPlayChecker);
console.warn("Checker Already Cleared. ptl")
listPlayChecker = setInterval(checkplay, 3000);
console.warn("Checker Already Set. ptl")
if(list.isEmpty()){
console.log("音乐列表没有歌曲哦,快加入新的音乐吧~");
alert("音乐列表没有歌曲哦,快加入新的音乐吧~");
@ -222,4 +268,64 @@ function gethistory(){
function removehistory(){
localStorage.removeItem("historyList");
gethistory();
}
// // 改变状态栏 -- Writtrn By Copilot
// function changeStatus(songname, artist){
// var oldTitle = document.title;
// document.title = `[Now Playing] ${songname} - ${artist}`;
// // 滚动显示
// var title = document.getElementById("title");
// title.innerHTML = `Playing ${songname} - ${artist}`;
// }
function changeTitle(status){
console.log(status + " title changed");
switch(status){
case "playing":
document.title = `[Now Playing] ${nowplaying.songname} - ${nowplaying.artist}`;
break;
case "paused":
document.title = `[Paused] ${nowplaying.songname} - ${nowplaying.artist}`;
break;
case "stopped":
document.title = `[Stopped] ${nowplaying.songname} - ${nowplaying.artist}`;
break;
default:
document.title = "[Music Player]";
}
}
function playstatChecking(){
console.log("playstatChecking");
var audio = document.getElementById("Player");
if (audio.paused) {
// 暂停
changeTitle("paused");
// 更改按钮状态
// var playbtn = document.getElementById("playbtn");
// playbtn.innerHTML = "播放";
// playbtn.setAttribute("onclick", "play()");
}else if(audio.ended){
// 停止
changeTitle("stopped");
// 更改按钮状态
// var playbtn = document.getElementById("playbtn");
// playbtn.innerHTML = "播放";
// playbtn.setAttribute("onclick", "play()");
}else if(audio.play){
// 播放
changeTitle("playing");
// 更改按钮状态
// var playbtn = document.getElementById("playbtn");
// playbtn.innerHTML = "暂停";
// playbtn.setAttribute("onclick", "pause()");
}else{
// 其他
changeTitle("");
// 更改按钮状态
// var playbtn = document.getElementById("playbtn");
// playbtn.innerHTML = "播放";
// playbtn.setAttribute("onclick", "play()");
}
}