Permalink
Browse files

Fix a bug that music cant't be played if there are more than 1 player…

…s in the article.
  • Loading branch information...
fly3949 committed Aug 31, 2016
1 parent 294adf3 commit 1a2f716664f2fb05e253dba965fc098decda2663
Showing with 47 additions and 34 deletions.
  1. +47 −34 class.hermit.php
@@ -107,7 +107,7 @@ public function shortcode( $atts, $content = null ) {
$apatts = $apatts . 'data-autoplay="' . (($atts[$value] == 1) ? "true" : "false") . '" ';
continue;
}
$apatts = $apatts . 'data-' . $value . '="' . $atts[$value] . '" ';
}
return '<!-Hermit X v' . HERMIT_VERSION . ' start--><div id="aplayer' . self::getUniqueId() . '" class="aplayer" ' . $apatts . '></div><!--Hermit X v' . HERMIT_VERSION . ' end-->';
@@ -173,7 +173,7 @@ public function hermit_callback() {
'msg' => $HMTJSON->netease_song_url( $id )
);
break;
case 'netease_pic_url' :
$result = array(
'status' => 200,
@@ -696,39 +696,52 @@ private function success_response( $result ) {
public function aplayer_init() {
echo "
<script>
var aps = document.getElementsByClassName('aplayer');
var ap = [];
remain_time = " . $this->settings( 'remainTime' ) . ";
for (var i = 0; i < aps.length; i++) {
var option = Object.assign({}, aps[i].dataset);
option.element = aps[i];
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
var response = JSON.parse(xhr.responseText);
option.music = response.msg.songs;
if (option.music[0].lrc) {
option.showlrc = 3;
}
else {
option.showlrc = 0;
}
if (option.music.length === 1) {
option.music = option.music[0];
}
ap[i] = new APlayer(option);
}
else {
console.log('Request was unsuccessful: ' + xhr.status);
}
}
};
var scope = option.songs.split('#:');
apiurl = '" . admin_url() . "admin-ajax.php?action=hermit&scope=' + option.songs.split('#:')[0] + '&id=' + option.songs.split('#:')[1];
xhr.open('get', apiurl, true);
xhr.send(null);
function hermitInit(){
var aps = document.getElementsByClassName('aplayer');
ap = [];
remain_time = 10;
for (var i = 0; i < aps.length; i++) {
var option = Object.assign({}, aps[i].dataset);
option.element = aps[i];
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
var response = JSON.parse(xhr.responseText);
option.music = response.msg.songs;
if (option.music[0].lrc) {
option.showlrc = 3;
}
else {
option.showlrc = 0;
}
if (option.music.length === 1) {
option.music = option.music[0];
}
ap[i] = new APlayer(option);
}
else {
console.log('Request was unsuccessful: ' + xhr.status);
}
}
};
var scope = option.songs.split('#:');
apiurl = 'https://www.wingsdream.cn/wp-admin/admin-ajax.php?action=hermit&scope=' + option.songs.split('#:')[0] + '&id=' + option.songs.split('#:')[1];
xhr.open('get', apiurl, false);
xhr.send(null);
}
}
function realoadHermit(){
for (var i = 0; i < ap.length; i++) {
try{
ap[i].pause();
} catch (e) {}
};
hermitInit();
}
hermitInit();
</script>";
}

0 comments on commit 1a2f716

Please sign in to comment.