【发布时间】:2017-09-07 09:40:58
【问题描述】:
这是我的代码:
$(document).on('click', 'div.play',function () {
play = $(this);
var stop = $('.stop');
contentId = play.attr('id');
nexttrack = nexttrackPlay(play);
if(!play.parent().hasClass('stop')) {
if(song ==undefined){
initAudio(play);
}
else
{
song.src = play.attr('audiourl');
song.load();
}
playerInit(play);
stop.each(function () {
$(this).removeClass('stop');
});
playAudio();
}
else{
if(song.paused){
playAudio();
}
else{
stopAudio();
}
}
});
function initAudio(elem) {
var url = elem.attr('audiourl');
song = document.getElementsByTagName('audio')[0];
console.log(song);
song.src = url;
song.preload = 'metadata';
song.load();
song.addEventListener('play', function () {
$('.play-play').addClass('stop');
play.parent().addClass('stop');
play.removeClass('pause');
$('.button-play').addClass('stop');
song.removeEventListener('play',function(){ });
},false);
song.addEventListener('pause', function () {
play.addClass('pause');
$('.play-play').removeClass('stop');
$('.button-play').removeClass('stop');
song.removeEventListener('play',function(){ });
},false);
}
function playAudio() {
song.load();
song.play();
}
function stopAudio() {
song.pause();
}
在 Android 和桌面上完美运行,但在 IOS 上第一次点击不起作用,当点击另一首歌曲然后再次开始播放时。
【问题讨论】:
-
我们需要的远不止这些