JS一个接一个地播放2个声音文件

时间:2018-02-09 22:48:14

标签: javascript html greasemonkey html5-audio

我正在尝试构建一个脚本(Greasemonkey),它将首先播放five.mp3然后在结束six.mp3之后播放 我正在使用下面的代码但两个文件同时播放 请为此提供解决方案

 var count = document.createElement('audio');
 count.src = "https://example.com/five.mp3";
 count.preload = 'auto';
 count.play();

 var x = document.createElement('audio');
 x.src = "https://example.com/six.mp3";
 x.preload = 'auto';
 x.play();

1 个答案:

答案 0 :(得分:-1)

以下示例说明如何在javascript中完成工作:

var count = document.createElement('audio');
count.src = "https://example.com/five.mp3";
count.preload = 'auto';
count.play();
count.onended=playSix;

function playSix()
{
  var x = document.createElement('audio');
  x.src = "https://example.com/six.mp3";
  x.preload = 'auto';
  x.play();
}