【发布时间】:2020-08-10 16:09:29
【问题描述】:
我正在尝试在 Microsoft Edge 中调用 Javascript Audio Play() 函数,但它无法正常工作,有时可以,有时不能。我在 Chrome 和 Firefox 中尝试了相同的代码,并且效果很好。只有 MS Edge 不稳定。
我使用小于 300 KB 剪辑的 mp3 文件。
let audioTrack = new Audio(file);
audioTrack.preload = 'auto';
console.log(audio file [${file}] length: ${audioTrack.duration} sec.);
audioTrack.onloadeddata = function () {
console.log(audio: ${file} has successfully loaded.);
};
audioTrack.play();
更新: 我更新了代码中的曲目列表:
<script>
var sounds = new Array(new Audio("http://www.orangefreesounds.com/wp-content/uploads/2020/04/Heavy-synth-loop-126-bpm.mp3?_=1"),
new Audio("http://www.orangefreesounds.com/wp-content/uploads/2020/04/Groove-synth-loop-130-bpm.mp3?_=1"),
new Audio("http://www.orangefreesounds.com/wp-content/uploads/2020/04/Mystical-loop-118-bpm.mp3?_=1"),
new Audio("http://www.orangefreesounds.com/wp-content/uploads/2020/04/New-generation-synth-loop-120.mp3?_=1"),
new Audio("http://www.orangefreesounds.com/wp-content/uploads/2020/03/Synth-arp-music-loop-118.mp3?_=1"),
new Audio("https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3"),
new Audio("http://soundbible.com/grab.php?id=2079&type=mp3"),
new Audio("http://www.music.helsinki.fi/tmt/opetus/uusmedia/esim/a2002011001-e02-128k.mp3"),
new Audio("http://techslides.com/demos/samples/sample.mp3")
);
var i = -1;
playSnd();
function playSnd() {
i++;
if (i == sounds.length) return;
sounds[i].onended = playSnd;
sounds[i].play();
};
</script>
它在 Edge 上运行良好,但我仍然不知道为什么在我的应用程序中仍然无法稳定运行。
【问题讨论】:
-
您使用的是哪个版本的 Microsoft Edge?我已经测试了我这边的Audio play() sample(使用 Microsoft Edge Chromium(版本 81.0.416.64(官方版本)(64 位))和 Microsoft Edge 44.18362.449.0),它们都运行良好。请检查一下。如果还是不行,请尝试使用F12开发者工具检查是否有错误?并尝试清除浏览器数据并重新检查。此外,最好发布足够的代码或创建示例来重现问题。
-
我的版本是“Microsoft Edge 44.18362.449.0, Microsoft EdgeHTML 18.18363”,如果您尝试使用单个文件,它会起作用,当您播放声音片段序列时会出现问题。前五个可能播放成功,但之后没有播放,控制台中也没有显示代码错误。
-
这是我写的示例代码:let audioTrack = new Audio(file); audioTrack.preload = '自动';控制台.log(
audio file [${file}] length: ${audioTrack.duration} sec.); audioTrack.onloadeddata = function () { console.log(audio: ${file} has successfully loaded.); }; audioTrack.load();
标签: javascript microsoft-edge html5-audio