我是一个业余程序员,我试图让一些东西工作,但我有点卡住了。希望有谁能帮我。
对于初学者来说,我使用wavesurfer来播放音频,效果很好。我已经启动了多个wavesurfer实例,除了一个引体向上之外,它们都运行得很好。当我在播放实例1的同时播放实例2的音频时,它的音频重叠,我不知道如何暂停实例1。
我尝试了几种方法,但最终还是一无所获,或者弄坏了wavesurfer。
这就是我现在发起的wavesurfer:
//getplayer
function getplayer(location)
{
var wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'white',
progressColor: 'cyan',
});
if (wavesurfer.isPlaying())
{
wavesurfer.pause();
wavesurfer.load(location);
wavesurfer.on('ready', function () {
wavesurfer.play();
});
}
else {
wavesurfer.load(location);
wavesurfer.on('ready', function () {
wavesurfer.play();
});
}
}为了将位置传递给函数,我使用ajax:
<script>
$(function() {
$('.playsong-".$i."').click(function(event) {
event.preventDefault();
$.ajax({
type: 'GET',
url: 'includes/ajax.php',
dataType :'html',
data : {songname : '" . $psong['sname'] . "', songpath : '" . $psong['sl'] . "'},
success : function(data){
$('#waveform').html(data);
}
})
});
});
</script> 然后将其传递给ajax.php文件并启动javascript:
<script>getplayer("<?= $location ?>")</script>我相信每次我调用wavesurfer时,我都会启动一个新的播放器实例,但我可能是错的……
谢谢你的帮忙!
发布于 2016-08-10 19:43:29
在我顿悟之后,似乎我是在做这件事,完全错了。
我实际上是在调用整个播放器的几个实例,而不是仅仅将信息传递给播放器。
我所做的是完全删除ajax调用。
然后我在歌曲按钮上添加了一个onclick处理程序,如下所示:
public function profilesongview($currentuser) {
$this->getmusic($currentuser);
$i = 1;
foreach ($this->musicarray as $psong) {
echo "<div class='col-md-12'>
<a href='#' class='playsong-" . $i . "' onclick=getplayer('".$psong['sl']."')><div class='profile_song'>
" . $psong['sname'] . "
</div></a></div>";
$i++;
}
}然后我将玩家的实例添加到站点的静态部分,一切都完成了!
https://stackoverflow.com/questions/38868887
复制相似问题