🔖v2.4 update

修复网易云音乐无法播放
增加标题栏滚动效果(感谢@lzcykevin)
增加歌曲循环播放控制(感谢@yuxizhe)
修复百度音乐无法播放
优化连续播放失败的歌曲过多时,自动终止播放。防止卡死
压缩图片素材,限制封面图片尺寸,优化页面加载速度
pull/25/merge
mengkun 2018-03-11 15:26:55 +08:00
parent 1197c3b23e
commit 6fc03396ad
12 changed files with 794 additions and 636 deletions

View File

@ -77,6 +77,14 @@ php 5.4+, curl_exec, file_get_contents, json_decode, openssl_encrypt
### 更新日志 ### 更新日志
----- -----
#### v2.4 `2018/3/11`
- 修复网易云音乐无法播放
- 增加标题栏滚动效果(感谢@lzcykevin)
- 增加歌曲循环播放控制(感谢@yuxizhe)
- 修复百度音乐无法播放
- 优化连续播放失败的歌曲过多时,自动终止播放。防止卡死
- 压缩图片素材,限制封面图片尺寸,优化页面加载速度
#### v2.32 `2017/9/15` #### v2.32 `2017/9/15`
- 修复播放历史记录歌曲时播放失败的 BUG - 修复播放历史记录歌曲时播放失败的 BUG
- 新增播放歌曲时浏览器标题栏显示相关信息 - 新增播放歌曲时浏览器标题栏显示相关信息

11
api.php
View File

@ -1,9 +1,9 @@
<?php <?php
/************************************************** /**************************************************
* MKOnlinePlayer v2.3 * MKOnlinePlayer v2.4
* 后台音乐数据抓取模块 * 后台音乐数据抓取模块
* 编写mengkun(https://mkblog.cn) * 编写mengkun(https://mkblog.cn)
* 时间2018-2-11 * 时间2018-3-11
* 特别感谢 @metowolf 提供的 Meting.php * 特别感谢 @metowolf 提供的 Meting.php
*************************************************/ *************************************************/
@ -22,7 +22,7 @@ $netease_cookie = '';
**/ **/
define('HTTPS', true); // 如果您的网站启用了https请将此项置为“true”如果你的网站未启用 https建议将此项设置为“false” define('HTTPS', false); // 如果您的网站启用了https请将此项置为“true”如果你的网站未启用 https建议将此项设置为“false”
define('DEBUG', false); // 是否开启调试模式正常使用时请将此项置为“false” define('DEBUG', false); // 是否开启调试模式正常使用时请将此项置为“false”
/* /*
@ -59,6 +59,11 @@ switch(getParam('types')) // 根据请求的 Api执行相应操作
$data = $API->url($id); $data = $API->url($id);
if($source == 'netease' && json_decode($data, true)['url'] == '') { // 修复网易云链接获取失效(双保险)
echojson('{"url":"https://music.163.com/song/media/outer/url?id='.$id.'.mp3","br":320}');
return;
}
echojson($data); echojson($data);
break; break;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.9 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -18,7 +18,7 @@
<meta name="x5-fullscreen" content="true"><!--QQ强制全屏--> <meta name="x5-fullscreen" content="true"><!--QQ强制全屏-->
<meta name="x5-page-mode" content="app"><!--QQ应用模式--> <meta name="x5-page-mode" content="app"><!--QQ应用模式-->
<title>MKOnlinePlayer v2.3</title> <title>MKOnlinePlayer v2.4</title>
<meta name="description" content="一款开源的基于网易云音乐api的在线音乐播放器。具有音乐搜索、播放、下载、歌词同步显示、个人音乐播放列表同步等功能。"/> <meta name="description" content="一款开源的基于网易云音乐api的在线音乐播放器。具有音乐搜索、播放、下载、歌词同步显示、个人音乐播放列表同步等功能。"/>
<meta name="keywords" content="孟坤播放器,在线音乐播放器,MKOnlinePlayer,网易云音乐,音乐api,音乐播放器源代码"/> <meta name="keywords" content="孟坤播放器,在线音乐播放器,MKOnlinePlayer,网易云音乐,音乐api,音乐播放器源代码"/>
@ -51,7 +51,7 @@
<!-- 头部logo --> <!-- 头部logo -->
<div class="header"> <div class="header">
<div class="logo" title="Version 2.32; Based on Meting; Powered by Mengkun"> <div class="logo" title="Version 2.4; Based on Meting; Powered by Mengkun">
♫ MKOnlinePlayer ♫ MKOnlinePlayer
</div> </div>
</div> <!--class="header"--> </div> <!--class="header"-->
@ -148,7 +148,7 @@
<!-- 站长统计代码 --> <!-- 站长统计代码 -->
<span style="display: none"> <span style="display: none">
<!-- 各类统计代码都放在这里…… --> <!-- 各类统计代码都放在这里…… -->
<script src="https://s95.cnzz.com/z_stat.php?id=1261525999&web_id=1261525999" language="JavaScript"></script>
</span> </span>
</body> </body>

View File

@ -1,8 +1,8 @@
/************************************************** /**************************************************
* MKOnlinePlayer v2.31 * MKOnlinePlayer v2.4
* Ajax 后台数据交互请求模块 * Ajax 后台数据交互请求模块
* 编写mengkun(http://mkblog.cn) * 编写mengkun(https://mkblog.cn)
* 时间2017-9-13 * 时间2018-3-11
*************************************************/ *************************************************/
// ajax加载搜索结果 // ajax加载搜索结果
@ -188,7 +188,7 @@ function ajaxPic(music, callback)
// ajax加载用户歌单 // ajax加载用户歌单
// 参数:歌单网易云 id, 歌单存储 id回调函数 // 参数:歌单网易云 id, 歌单存储 id回调函数
function ajaxPlayList(lid, id, callback){ function ajaxPlayList(lid, id, callback) {
if(!lid) return false; if(!lid) return false;
// 已经在加载了,跳过 // 已经在加载了,跳过
@ -218,7 +218,7 @@ function ajaxPlayList(lid, id, callback){
}; };
if(jsonData.playlist.coverImgUrl !== '') { if(jsonData.playlist.coverImgUrl !== '') {
tempList.cover = jsonData.playlist.coverImgUrl; tempList.cover = jsonData.playlist.coverImgUrl + "?param=200y200";
} else { } else {
tempList.cover = musicList[id].cover; tempList.cover = musicList[id].cover;
} }
@ -235,7 +235,7 @@ function ajaxPlayList(lid, id, callback){
url_id: jsonData.playlist.tracks[i].id, // 链接ID url_id: jsonData.playlist.tracks[i].id, // 链接ID
pic_id: null, // 封面ID pic_id: null, // 封面ID
lyric_id: jsonData.playlist.tracks[i].id, // 歌词ID lyric_id: jsonData.playlist.tracks[i].id, // 歌词ID
pic: jsonData.playlist.tracks[i].al.picUrl, // 专辑图片 pic: jsonData.playlist.tracks[i].al.picUrl + "?param=300y300", // 专辑图片
url: null // mp3链接 url: null // mp3链接
}; };
} }
@ -354,7 +354,7 @@ function ajaxUserList(uid)
tempList = { tempList = {
id: jsonData.playlist[i].id, // 列表的网易云 id id: jsonData.playlist[i].id, // 列表的网易云 id
name: jsonData.playlist[i].name, // 列表名字 name: jsonData.playlist[i].name, // 列表名字
cover: jsonData.playlist[i].coverImgUrl, // 列表封面 cover: jsonData.playlist[i].coverImgUrl + "?param=200y200", // 列表封面
creatorID: uid, // 列表创建者id creatorID: uid, // 列表创建者id
creatorName: jsonData.playlist[i].creator.nickname, // 列表创建者名字 creatorName: jsonData.playlist[i].creator.nickname, // 列表创建者名字
creatorAvatar: jsonData.playlist[i].creator.avatarUrl, // 列表创建者头像 creatorAvatar: jsonData.playlist[i].creator.avatarUrl, // 列表创建者头像

View File

@ -1,8 +1,8 @@
/************************************************** /**************************************************
* MKOnlinePlayer v2.32 * MKOnlinePlayer v2.4
* 封装函数及UI交互模块 * 封装函数及UI交互模块
* 编写mengkun(http://mkblog.cn) * 编写mengkun(https://mkblog.cn)
* 时间2017-9-15 * 时间2018-3-11
*************************************************/ *************************************************/
// 判断是否是移动设备 // 判断是否是移动设备
var isMobile = { var isMobile = {
@ -28,8 +28,9 @@ $(function(){
console.warn('播放器调试模式已开启,正常使用时请在 js/player.js 中按说明关闭调试模式'); console.warn('播放器调试模式已开启,正常使用时请在 js/player.js 中按说明关闭调试模式');
} }
rem.isMobile = isMobile.any(); rem.isMobile = isMobile.any(); // 判断是否是移动设备
rem.webTitle = document.title; // 记录页面原本的标题 rem.webTitle = document.title; // 记录页面原本的标题
rem.errCount = 0; // 连续播放失败的歌曲数归零
initProgress(); // 初始化音量条、进度条(进度条初始化要在 Audio 前,别问我为什么……) initProgress(); // 初始化音量条、进度条(进度条初始化要在 Audio 前,别问我为什么……)
initAudio(); // 初始化 audio 标签,事件绑定 initAudio(); // 初始化 audio 标签,事件绑定
@ -397,6 +398,7 @@ function openDownloadDialog(url, saveName)
} }
var aLink = document.createElement('a'); var aLink = document.createElement('a');
aLink.href = url; aLink.href = url;
aLink.target = "_blank";
aLink.download = saveName || ''; // HTML5新增的属性指定保存文件名可以不要后缀注意file:///模式下不会生效 aLink.download = saveName || ''; // HTML5新增的属性指定保存文件名可以不要后缀注意file:///模式下不会生效
var event; var event;
if(window.MouseEvent) event = new MouseEvent('click'); if(window.MouseEvent) event = new MouseEvent('click');

View File

@ -1,8 +1,8 @@
/************************************************** /**************************************************
* MKOnlinePlayer v2.32 * MKOnlinePlayer v2.4
* 播放器主功能模块 * 播放器主功能模块
* 编写mengkun(https://mkblog.cn) * 编写mengkun(https://mkblog.cn)
* 时间2018-2-11 * 时间2018-3-11
*************************************************/ *************************************************/
// 播放器功能配置 // 播放器功能配置
var mkPlayer = { var mkPlayer = {
@ -16,7 +16,7 @@ var mkPlayer = {
dotshine: true, // 是否开启播放进度条的小点闪动效果[不支持IE](true/false) *开启后会有些卡 dotshine: true, // 是否开启播放进度条的小点闪动效果[不支持IE](true/false) *开启后会有些卡
mdotshine: false, // 是否开启[移动端]播放进度条的小点闪动效果[不支持IE](true/false) mdotshine: false, // 是否开启[移动端]播放进度条的小点闪动效果[不支持IE](true/false)
volume: 0.6, // 默认音量值(0~1之间) volume: 0.6, // 默认音量值(0~1之间)
version: "v2.32", // 播放器当前版本号(仅供调试) version: "v2.4", // 播放器当前版本号(仅供调试)
debug: false // 是否开启调试模式(true/false) debug: false // 是否开启调试模式(true/false)
}; };
@ -36,8 +36,14 @@ function audioErr() {
// 没播放过,直接跳过 // 没播放过,直接跳过
if(rem.playlist === undefined) return true; if(rem.playlist === undefined) return true;
layer.msg('当前歌曲播放失败,自动播放下一首'); if(rem.errCount > 10) { // 连续播放失败的歌曲过多
nextMusic(); // 切换下一首歌 layer.msg('似乎出了点问题~播放已停止');
rem.errCount = 0;
} else {
rem.errCount++; // 记录连续播放失败的歌曲数目
layer.msg('当前歌曲播放失败,自动播放下一首');
nextMusic(); // 切换下一首歌
}
} }
// 点击暂停按钮的事件 // 点击暂停按钮的事件
@ -62,29 +68,29 @@ function pause() {
// 循环顺序 // 循环顺序
function orderChange() { function orderChange() {
if(!rem.order){ if(!rem.order) rem.order = 2;
rem.order = 2 rem.order++;
} if(rem.order > 3) rem.order = 1;
rem.order++;
if(rem.order > 3){ var orderDiv = $(".btn-order");
rem.order = 1 orderDiv.removeClass();
} switch(rem.order) {
var orderDiv = $(".btn-order") case 1: // 单曲循环
orderDiv.removeClass() orderDiv.addClass("player-btn btn-order btn-order-single");
orderDiv.attr("title","单曲循环");
if ( 1 === rem.order ) { break;
orderDiv.addClass("player-btn btn-order btn-order-single")
orderDiv.attr("title","单曲循环") case 3: // 随机播放
} orderDiv.addClass("player-btn btn-order btn-order-random");
else if ( 2 === rem.order ) { orderDiv.attr("title","随机播放");
orderDiv.addClass("player-btn btn-order btn-order-list") break;
orderDiv.attr("title","列表循环")
} default: // 顺序播放
else if ( 3 === rem.order ) { orderDiv.addClass("player-btn btn-order btn-order-list");
orderDiv.addClass("player-btn btn-order btn-order-random") orderDiv.attr("title","列表循环");
orderDiv.attr("title","随机播放") }
}
} }
// 播放 // 播放
function audioPlay() { function audioPlay() {
rem.paused = false; // 更新状态(未暂停) rem.paused = false; // 更新状态(未暂停)
@ -142,28 +148,28 @@ function prevMusic() {
// 播放下一首歌 // 播放下一首歌
function nextMusic() { function nextMusic() {
switch (rem.order ? rem.order : 1) { switch (rem.order ? rem.order : 1) {
case 1,2: case 1,2:
playList(rem.playid + 1); playList(rem.playid + 1);
break; break;
case 3: case 3:
if (musicList[1] && musicList[1].item.length) { if (musicList[1] && musicList[1].item.length) {
var id = parseInt(Math.random() * musicList[1].item.length) var id = parseInt(Math.random() * musicList[1].item.length);
playList(id); playList(id);
} }
break; break;
default: default:
playList(rem.playid + 1); playList(rem.playid + 1);
break; break;
} }
} }
// 自动播放时的下一首歌 // 自动播放时的下一首歌
function autoNextMusic() { function autoNextMusic() {
if(rem.order && rem.order === 1) { if(rem.order && rem.order === 1) {
playList(rem.playid); playList(rem.playid);
} else { } else {
nextMusic() nextMusic();
} }
} }
// 歌曲时间变动回调函数 // 歌曲时间变动回调函数
@ -328,6 +334,7 @@ function play(music) {
return; return;
} }
rem.errCount = 0; // 连续播放失败的歌曲数归零
music_bar.goto(0); // 进度条强制归零 music_bar.goto(0); // 进度条强制归零
changeCover(music); // 更新封面展示 changeCover(music); // 更新封面展示
ajaxLyric(music, lyricCallback); // ajax加载歌词 ajaxLyric(music, lyricCallback); // ajax加载歌词
@ -337,7 +344,7 @@ function play(music) {
// 我的要求并不高,保留这一句版权信息可好? // 我的要求并不高,保留这一句版权信息可好?
// 保留了,你不会损失什么;而保留版权,是对作者最大的尊重。 // 保留了,你不会损失什么;而保留版权,是对作者最大的尊重。
console.info('欢迎使用 MKOnlinePlayer!\n当前版本'+mkPlayer.version+' \n作者mengkun(http://mkblog.cn)\n歌曲来源于各大音乐平台\nGithubhttps://github.com/mengkunsoft/MKOnlineMusicPlayer'); console.info('欢迎使用 MKOnlinePlayer!\n当前版本'+mkPlayer.version+' \n作者mengkun(https://mkblog.cn)\n歌曲来源于各大音乐平台\nGithubhttps://github.com/mengkunsoft/MKOnlineMusicPlayer');
// 音乐进度条拖动回调函数 // 音乐进度条拖动回调函数
function mBcallback(newVal) { function mBcallback(newVal) {

File diff suppressed because it is too large Load Diff