2020-10-21 18:05:33 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
|
|
<title>来点Music~</title>
|
|
|
|
<link rel="stylesheet" href="/layui/css/layui.css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="layui-layout layui-layout-admin">
|
|
|
|
<div id="header"></div>
|
2020-10-23 17:55:56 +08:00
|
|
|
|
2021-07-04 12:24:52 +08:00
|
|
|
<div class="layui-body" style="left: 200px;overflow:auto;">
|
2021-02-23 11:16:56 +08:00
|
|
|
<!-- <div id="side"></div>-->
|
2020-10-21 23:25:29 +08:00
|
|
|
|
|
|
|
<div style="margin-left: 2%; margin-top: 2%;">
|
2020-10-21 18:05:33 +08:00
|
|
|
<div>
|
2020-10-21 23:25:29 +08:00
|
|
|
<img src="/assets/defaultPlayImg.jpg" id="img" style="height: 200px; width: 200px"/>
|
|
|
|
|
2020-10-21 18:05:33 +08:00
|
|
|
<div style="display:inline-block;">
|
2020-10-29 09:58:43 +08:00
|
|
|
<div id="musicSize">歌单总数:</div>
|
2020-10-26 18:32:35 +08:00
|
|
|
<div id="playerNowList">播放列表:</div>
|
2020-10-23 17:55:56 +08:00
|
|
|
<div id="title">标题:</div>
|
|
|
|
<div id="artist">艺术家:</div>
|
|
|
|
<div id="album">专辑:</div>
|
|
|
|
<div id="composer">作曲家</div>
|
2020-10-26 16:50:16 +08:00
|
|
|
<a class="layui-btn layui-btn-normal" id="download">下载</a>
|
2020-10-26 18:32:35 +08:00
|
|
|
<a class="layui-btn layui-btn-normal" id="next">下一首</a>
|
2020-10-21 18:05:33 +08:00
|
|
|
</div>
|
2020-10-21 23:25:29 +08:00
|
|
|
|
|
|
|
<div id="audioWrap"></div>
|
|
|
|
|
2020-10-21 18:05:33 +08:00
|
|
|
</div>
|
2020-10-23 17:55:56 +08:00
|
|
|
<table id="playlist" lay-filter="music"></table>
|
2020-10-26 23:43:20 +08:00
|
|
|
<a class="layui-btn layui-btn-normal" id="reload">刷新曲库</a>
|
2020-10-21 18:05:33 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="footer"></div>
|
|
|
|
</div>
|
2020-10-23 17:55:56 +08:00
|
|
|
|
2020-10-21 18:05:33 +08:00
|
|
|
</div>
|
|
|
|
<script src="/layui/layui.js"></script>
|
|
|
|
<script src="/js/jquery-3.2.1.js"></script>
|
2020-10-21 23:25:29 +08:00
|
|
|
<script src="/js/myjs.js"></script>
|
|
|
|
<link rel="stylesheet" href="/css/AudioPlayer.css">
|
|
|
|
<script src="/js/AudioPlayer.js"></script>
|
2020-10-26 16:50:16 +08:00
|
|
|
<script id="listTemplet">
|
2020-11-27 18:33:21 +08:00
|
|
|
{{# if(d.isdir===1){ }}
|
2020-10-26 18:32:35 +08:00
|
|
|
<div><i class="layui-icon"> </i>{{d.title}}</div>
|
2020-10-26 16:50:16 +08:00
|
|
|
{{# } else { }}
|
2020-10-26 18:32:35 +08:00
|
|
|
<div><i class="layui-icon"> </i>{{d.title}}</div>
|
2020-10-26 16:50:16 +08:00
|
|
|
{{# } }}
|
|
|
|
</script>
|
|
|
|
<script type="text/html" id="music">
|
|
|
|
<a class="layui-btn layui-btn-xs" lay-event="download">下载</a>
|
2020-10-26 18:32:35 +08:00
|
|
|
<a class="layui-btn layui-btn-xs" lay-event="play">播放</a>
|
2020-10-26 16:50:16 +08:00
|
|
|
</script>
|
2020-10-21 18:05:33 +08:00
|
|
|
<script>
|
2020-10-23 17:55:56 +08:00
|
|
|
let localhost = "";
|
2020-10-26 18:32:35 +08:00
|
|
|
let musicLib = []
|
|
|
|
let isRandom = true;
|
|
|
|
let playIndex = 0;
|
|
|
|
let playNow = ""
|
|
|
|
$.get("/nas/music/getlocalhost.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk", function (obj) {
|
|
|
|
try {
|
|
|
|
let json = JSON.parse(obj);
|
2020-12-04 14:09:12 +08:00
|
|
|
localhost = json.data + ":8000";
|
|
|
|
console.log("音频地址:" + localhost)
|
|
|
|
if (localhost === 'http://null:8000' || localhost === ":8000") {
|
|
|
|
localhost = "http://127.0.0.1"
|
2020-10-26 18:32:35 +08:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
localhost = ""
|
|
|
|
}
|
2020-12-24 18:36:28 +08:00
|
|
|
// localhost = "http://113.109.23.240:8000";
|
2020-10-26 17:11:23 +08:00
|
|
|
layui.use(['table', 'element'], function () {
|
|
|
|
let table = layui.table;
|
|
|
|
let element = layui.element;
|
2020-10-26 18:32:35 +08:00
|
|
|
let listTable = table.render({
|
2020-10-26 17:11:23 +08:00
|
|
|
elem: '#playlist'
|
|
|
|
, url: localhost + '/nas/music/list.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk' //数据接口
|
2020-12-04 14:09:12 +08:00
|
|
|
, method: 'post'
|
|
|
|
, where: {
|
|
|
|
path: 'root',
|
|
|
|
type: false
|
|
|
|
}
|
|
|
|
, contentType: 'application/json'
|
2020-10-26 17:11:23 +08:00
|
|
|
, page: true //开启分页
|
|
|
|
, cols: [[
|
2020-12-04 14:09:12 +08:00
|
|
|
{field: 'title', title: '标题', width: 400, sort: true, templet: "#listTemplet"}
|
2020-10-26 17:11:23 +08:00
|
|
|
, {field: 'artist', title: '艺术家', width: 200}
|
|
|
|
, {field: 'album', title: '专辑', width: 200}
|
|
|
|
, {field: 'composer', title: '作曲', width: 200}
|
2020-12-04 14:09:12 +08:00
|
|
|
, {field: 'track', title: '音轨号', width: 100, sort: true}
|
2020-10-26 18:32:35 +08:00
|
|
|
, {field: "right", width: 150, toolbar: '#music'}
|
2020-10-26 17:11:23 +08:00
|
|
|
]]
|
2020-10-26 18:32:35 +08:00
|
|
|
, done: function (res, curr, count) {
|
|
|
|
musicLib = res.data
|
2020-12-04 14:09:12 +08:00
|
|
|
$('#musicSize').html("歌单总数:" + res.size)
|
2020-10-26 17:11:23 +08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
table.on('rowDouble(music)', function (obj) {
|
|
|
|
//obj 同上
|
2020-12-04 14:09:12 +08:00
|
|
|
if (obj.data.isdir === 1) {
|
2020-10-26 17:11:23 +08:00
|
|
|
listTable.reload({
|
2020-10-26 18:32:35 +08:00
|
|
|
where: {
|
|
|
|
path: obj.data.file
|
2020-10-26 17:11:23 +08:00
|
|
|
}
|
2020-10-26 18:32:35 +08:00
|
|
|
, page: {
|
|
|
|
curr: 1
|
2020-10-26 17:11:23 +08:00
|
|
|
}
|
|
|
|
});
|
2020-10-26 18:32:35 +08:00
|
|
|
} else {
|
|
|
|
isRandom = false;
|
|
|
|
playIndex = obj.tr[0].dataset.index;
|
2020-10-26 17:11:23 +08:00
|
|
|
play(obj.data.file)
|
|
|
|
}
|
2020-10-26 16:50:16 +08:00
|
|
|
|
2020-10-26 17:11:23 +08:00
|
|
|
});
|
2020-10-26 16:50:16 +08:00
|
|
|
|
2020-10-26 17:11:23 +08:00
|
|
|
table.on('tool(music)', function (obj) {
|
|
|
|
let data = obj.data;
|
2020-10-26 18:32:35 +08:00
|
|
|
if (obj.event === 'download') {
|
2020-12-04 14:09:12 +08:00
|
|
|
if (data.isdir === 0) {
|
2020-10-26 18:32:35 +08:00
|
|
|
window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + new Base64().encode(data.file))
|
2020-10-26 17:11:23 +08:00
|
|
|
}
|
2020-10-26 18:32:35 +08:00
|
|
|
} else if (obj.event === 'play') {
|
2020-12-24 18:36:28 +08:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url:localhost + "/nas/music/list.do",
|
|
|
|
contentType: "application/json; charset=utf-8",
|
|
|
|
data:JSON.stringify({type: true, path: data.file}),
|
|
|
|
dataType: "json",
|
|
|
|
success:function (json){
|
|
|
|
try {
|
|
|
|
if (json.code === 0) {
|
|
|
|
playIndex = 0;
|
|
|
|
musicLib=[]
|
|
|
|
for (let datum of json.data) {
|
|
|
|
if(datum.isdir===0){
|
|
|
|
musicLib.push(datum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isRandom = false;
|
|
|
|
playNext()
|
|
|
|
}
|
|
|
|
}catch (e){
|
|
|
|
|
|
|
|
}
|
2020-10-26 16:50:16 +08:00
|
|
|
|
2020-12-24 18:36:28 +08:00
|
|
|
}
|
2020-10-26 18:32:35 +08:00
|
|
|
})
|
2020-10-26 17:11:23 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
element.on('nav(menus)', function (elem) {
|
|
|
|
});
|
2020-10-23 17:55:56 +08:00
|
|
|
});
|
|
|
|
|
2020-10-27 00:32:55 +08:00
|
|
|
});
|
2020-10-26 17:11:23 +08:00
|
|
|
|
2020-10-21 23:25:29 +08:00
|
|
|
let player = $.AudioPlayer;
|
|
|
|
player.init({
|
|
|
|
container: '#audioWrap'
|
|
|
|
, source: ''
|
2020-12-04 14:09:12 +08:00
|
|
|
, imagePath: '/assets'
|
2020-10-21 23:25:29 +08:00
|
|
|
, debuggers: false
|
|
|
|
, allowSeek: true
|
|
|
|
, endedCallback: function () {
|
|
|
|
console.log('播放完成')
|
2020-10-26 18:32:35 +08:00
|
|
|
if (isRandom) {
|
2020-10-26 16:50:16 +08:00
|
|
|
random()
|
2020-10-26 18:32:35 +08:00
|
|
|
} else {
|
2020-10-26 16:50:16 +08:00
|
|
|
playNext()
|
|
|
|
}
|
|
|
|
|
2020-10-23 17:55:56 +08:00
|
|
|
}, canplayCallback: function () {
|
2020-10-21 23:25:29 +08:00
|
|
|
console.log("点击播放")
|
|
|
|
}
|
|
|
|
});
|
2020-10-21 18:05:33 +08:00
|
|
|
$.ajax({cache: false})
|
|
|
|
$('#header').load("/html/header.html");
|
|
|
|
$('#footer').load("/html/footer.html");
|
|
|
|
$('#side').load("/html/body/nas/side.html");
|
2020-10-21 23:25:29 +08:00
|
|
|
$('#img').click(function () {
|
2020-10-26 18:32:35 +08:00
|
|
|
isRandom = true;
|
2020-10-21 23:25:29 +08:00
|
|
|
random()
|
|
|
|
});
|
2020-10-26 18:32:35 +08:00
|
|
|
$('#download').click(function () {
|
|
|
|
window.open(localhost + "/nas/music/play.do?token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk&random=false&filePath=" + playNow)
|
2020-10-26 23:43:20 +08:00
|
|
|
});
|
2020-12-04 14:09:12 +08:00
|
|
|
$('#next').click(function () {
|
2020-10-26 18:32:35 +08:00
|
|
|
playNext()
|
2020-10-26 23:43:20 +08:00
|
|
|
});
|
2020-12-04 14:09:12 +08:00
|
|
|
$('#reload').click(function () {
|
|
|
|
$.post(localhost + "/nas/music/reload.do", function (obj) {
|
2020-10-29 10:01:03 +08:00
|
|
|
layer.msg("提交刷新请求成功,几分钟后生效")
|
|
|
|
})
|
2020-10-26 23:43:20 +08:00
|
|
|
});
|
2020-10-21 23:25:29 +08:00
|
|
|
|
2020-10-26 16:50:16 +08:00
|
|
|
|
2020-10-26 18:32:35 +08:00
|
|
|
function playNext() {
|
2020-12-04 14:09:12 +08:00
|
|
|
if (isRandom) {
|
2020-10-26 18:32:35 +08:00
|
|
|
random()
|
2020-12-04 14:09:12 +08:00
|
|
|
return;
|
2020-10-26 18:32:35 +08:00
|
|
|
}
|
|
|
|
if (playIndex === musicLib.length) {
|
|
|
|
playIndex = 0;
|
2020-10-26 16:50:16 +08:00
|
|
|
}
|
2020-12-04 14:09:12 +08:00
|
|
|
if (musicLib[playIndex].isdir === 1) {
|
2020-10-26 16:50:16 +08:00
|
|
|
playIndex++
|
|
|
|
playNext()
|
2020-10-26 18:32:35 +08:00
|
|
|
} else {
|
2020-10-26 16:50:16 +08:00
|
|
|
play(musicLib[playIndex].file);
|
|
|
|
playIndex++
|
|
|
|
}
|
2020-10-23 17:55:56 +08:00
|
|
|
}
|
|
|
|
|
2020-10-21 23:25:29 +08:00
|
|
|
function random() {
|
2020-12-04 14:09:12 +08:00
|
|
|
$.post(localhost + "/nas/music/random.do", function (data) {
|
2020-10-21 18:05:33 +08:00
|
|
|
let json = JSON.parse(data)
|
2020-10-26 16:50:16 +08:00
|
|
|
if (json.code === 0) {
|
2020-10-26 18:32:35 +08:00
|
|
|
playNow = json.data
|
2020-10-21 23:25:29 +08:00
|
|
|
player.updateSource({
|
2020-10-26 18:32:35 +08:00
|
|
|
source: localhost + "/nas/music/play.do?random=false&filePath=" + json.data + "&token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk"
|
2020-10-21 23:25:29 +08:00
|
|
|
});
|
|
|
|
update(json.data)
|
|
|
|
player.play()
|
|
|
|
|
2020-10-21 18:05:33 +08:00
|
|
|
} else {
|
|
|
|
layer.msg(json.msg)
|
|
|
|
}
|
|
|
|
})
|
2020-10-21 23:25:29 +08:00
|
|
|
}
|
2020-10-23 17:55:56 +08:00
|
|
|
|
2020-10-21 23:25:29 +08:00
|
|
|
function play(file) {
|
2020-10-23 17:55:56 +08:00
|
|
|
let filePath = escape(new Base64().encode(file))
|
2020-10-26 18:32:35 +08:00
|
|
|
playNow = filePath
|
2020-10-21 23:25:29 +08:00
|
|
|
player.updateSource({
|
2020-10-26 18:32:35 +08:00
|
|
|
source: localhost + "/nas/music/play.do?random=false&filePath=" + filePath + "&token=PlVodzYhvxRQbOHKakpKs2dvnoc43Cnk"
|
2020-10-21 23:25:29 +08:00
|
|
|
});
|
|
|
|
update(filePath)
|
|
|
|
player.play()
|
|
|
|
}
|
2020-10-23 17:55:56 +08:00
|
|
|
|
2020-10-21 23:25:29 +08:00
|
|
|
function update(fileName) {
|
2020-12-04 14:09:12 +08:00
|
|
|
$.ajax({
|
|
|
|
type: 'post'
|
|
|
|
, url: localhost + '/nas/music/find/file.do'
|
|
|
|
, contentType: "application/json"
|
|
|
|
, data: JSON.stringify({"path": fileName})
|
|
|
|
, success: function (data) {
|
|
|
|
let json = JSON.parse(data);
|
|
|
|
if (isRandom) {
|
|
|
|
$('#playerNowList').html("播放列表: (全列表随机播放)")
|
|
|
|
} else {
|
|
|
|
$('#playerNowList').html("播放列表: (" + playIndex + "/" + musicLib.length + ")")
|
|
|
|
}
|
|
|
|
$('#title').html("标题:" + json.data.title)
|
|
|
|
$('#artist').html("艺术家:" + json.data.artist)
|
|
|
|
$('#album').html("专辑:" + json.data.album)
|
|
|
|
$('#composer').html("作曲:" + json.data.composer)
|
|
|
|
navigator.mediaSession.metadata = new MediaMetadata({
|
|
|
|
title: json.data.title,
|
|
|
|
artist: json.data.artist,
|
|
|
|
album: json.data.album,
|
|
|
|
artwork:[
|
|
|
|
{
|
|
|
|
src: localhost+'/nas/music/web/image.do?fileName='+fileName,
|
|
|
|
type: 'image/png',
|
|
|
|
sizes: '128x128'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
navigator.mediaSession.setActionHandler('nexttrack', function () {
|
|
|
|
// 用户点击了“下一首”媒体通知图标
|
|
|
|
playNext();
|
|
|
|
});
|
2020-10-26 18:32:35 +08:00
|
|
|
}
|
2020-10-21 23:25:29 +08:00
|
|
|
})
|
2020-12-24 18:36:28 +08:00
|
|
|
$('#img').attr("src",localhost+'/nas/music/web/image.do?fileName='+fileName);
|
2020-10-21 23:25:29 +08:00
|
|
|
}
|
2020-10-21 18:05:33 +08:00
|
|
|
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
|
|
|
|
</style>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|