Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix api.php phpdoc,fix “Uncaught (in promise):” error #64

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
cache/*
17 changes: 9 additions & 8 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
**/


define('HTTPS', false); // 如果您的网站启用了https,请将此项置为“true”,如果你的网站未启用 https,建议将此项设置为“false”
define('HTTPS', true); // 如果您的网站启用了https,请将此项置为“true”,如果你的网站未启用 https,建议将此项设置为“false”
define('DEBUG', false); // 是否开启调试模式,正常使用时请将此项置为“false”
define('CACHE_PATH', 'cache/'); // 文件缓存目录,请确保该目录存在且有读写权限。如无需缓存,可将此行注释掉

Expand Down Expand Up @@ -172,16 +172,17 @@

/**
* 创建多层文件夹
* @param $dir 路径
* @param string $dir 路径
* @return bool
*/
function createFolders($dir) {
return is_dir($dir) or (createFolders(dirname($dir)) and mkdir($dir, 0755));
}

/**
* 检测服务器函数支持情况
* @param $f 函数名
* @param $m 是否为必须函数
* @param string $f 函数名
* @param bool $m 是否为必须函数
* @return
*/
function checkfunc($f,$m = false) {
Expand All @@ -198,9 +199,9 @@ function checkfunc($f,$m = false) {

/**
* 获取GET或POST过来的参数
* @param $key 键值
* @param $default 默认值
* @return 获取到的内容(没有则为默认值)
* @param string $key 键值
* @param string $default 默认值
* @return string 获取到的内容(没有则为默认值)
*/
function getParam($key, $default='')
{
Expand All @@ -209,7 +210,7 @@ function getParam($key, $default='')

/**
* 输出一个json或jsonp格式的内容
* @param $data 数组内容
* @param string $data 数组内容
*/
function echojson($data) //json和jsonp通用
{
Expand Down
82 changes: 70 additions & 12 deletions js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var mkPlayer = {
debug: false // 是否开启调试模式(true/false)
};


let playPromise;

/*******************************************************
* 以下内容是播放器核心文件,不建议进行修改,否则可能导致播放器无法正常使用!
Expand Down Expand Up @@ -49,7 +49,18 @@ function audioErr() {
// 点击暂停按钮的事件
function pause() {
if(rem.paused === false) { // 之前是播放状态
rem.audio[0].pause(); // 暂停
playPromise = rem.audio[0].pause();
if (playPromise) {
playPromise.then(function(){
// 音频加载成功
// 音频的播放需要耗时
setTimeout(function(){
// 后续操作
}, rem.duration * 1000);
}).catch((e) => {
// 音频加载失败
});
}
} else {
// 第一次点播放
if(rem.playlist === undefined) {
Expand All @@ -62,7 +73,18 @@ function pause() {

listClick(0);
}
rem.audio[0].play();
playPromise = rem.audio[0].play();
if (playPromise) {
playPromise.then(function(){
// 音频加载成功
// 音频的播放需要耗时
setTimeout(function(){
// 后续操作
}, rem.duration * 1000);
}).catch((e) => {
// 音频加载失败
});
}
}
}

Expand Down Expand Up @@ -144,27 +166,41 @@ function audioPause() {
document.title = rem.webTitle; // 改变浏览器标题
}

let prevPlayId = false;
// 播放上一首歌
function prevMusic() {
playList(rem.playid - 1);
let id = rem.playid - 1;
switch (rem.order ? rem.order : 1) {
case 3:
if(! prevPlayId)
{
layer.msg('点错了吧?你还没听过歌呢~');
break;
}
if(prevPlayId == rem.playid)
{
nextMusic();
break;
}
id = prevPlayId;
break;
}
playList(id);
}

// 播放下一首歌
function nextMusic() {
prevPlayId = rem.playid;
let id = rem.playid + 1;
switch (rem.order ? rem.order : 1) {
case 1,2:
playList(rem.playid + 1);
break;
case 3:
if (musicList[1] && musicList[1].item.length) {
var id = parseInt(Math.random() * musicList[1].item.length);
id = parseInt(Math.random() * musicList[1].item.length);
playList(id);
}
break;
default:
playList(rem.playid + 1);
break;
}
playList(id);
}
// 自动播放时的下一首歌
function autoNextMusic() {
Expand All @@ -175,6 +211,7 @@ function autoNextMusic() {
}
}


// 歌曲时间变动回调函数
function updateProgress(){
// 暂停状态不管
Expand Down Expand Up @@ -269,6 +306,16 @@ function playList(id) {
} else {
play(musicList[1].item[id]);
}

var position = parseInt(id * 50);
if(rem.isMobile)
{
$('#main-list').animate({scrollTop:position}, 800);
}
else
{
$("#main-list").mCustomScrollbar("scrollTo",position);
}
}

// 初始化 Audio
Expand Down Expand Up @@ -323,7 +370,18 @@ function play(music) {
try {
rem.audio[0].pause();
rem.audio.attr('src', music.url);
rem.audio[0].play();
playPromise = rem.audio[0].play();
if (playPromise) {
playPromise.then(function(){
// 音频加载成功
// 音频的播放需要耗时
setTimeout(function(){
// 后续操作
}, rem.duration * 1000);
}).catch((e) => {
// 音频加载失败
});
}
} catch(e) {
audioErr(); // 调用错误处理函数
return;
Expand Down