gpt4 book ai didi

flash - 浏览器中循环音频的最佳方法?

转载 作者:行者123 更新时间:2023-12-03 00:19:08 24 4
gpt4 key购买 nike

我正在制作一个涉及许多多轨音频循环的网站。
我想知道(用javascript等)实现这些的最佳方法是什么?

我应该使用:
-flash或一些相关的Flash库

要么

-html5音频

或者是其他东西?

音频循环是无缝的,这一点非常重要

有哪些好的库?过去,我曾使用过音效管理器。
这些文件将主要是mp3。

最佳答案

如果您愿意使用WebKit浏览器,则可以使用Web Audio API。

这是一些样板代码“抽象”,可以帮助您入门。需要一台服务器。

<!DOCTYPE html>
<meta charset="UTF-8">
<title></title>

<div id="kickDrum"> </div> // click and will loop
<div id="snareDrum"></div> // Won't loop




<script>
var kickDrum = new audioApiKey("kickDrum","kick.mp3",true); // first argument is the div name, the next is the audio file name & url the last parameter is loop on/off. true means loop on

var snareDrum = new audioApiKey("snareDrum","snare.mp3", false);





// Below is the abstracted guts.

var context = new webkitAudioContext();

function audioApiKey(domNode,fileDirectory,loopOnOff) {
this.domNode = domNode;
this.fileDirectory = fileDirectory;
this.loopOnOff = loopOnOff;
var bufferFunctionName = bufferFunctionName;
var incomingBuffer;
var savedBuffer;
var xhr;
bufferFunctionName = function () {
var source = context.createBufferSource();
source.buffer = savedBuffer;
source.loop = loopOnOff;
source.connect(context.destination);
source.noteOn(0); // Play sound immediately
};
var xhr = new XMLHttpRequest();
xhr.open('get',fileDirectory, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
context.decodeAudioData(xhr.response,
function(incomingBuffer) {
savedBuffer = incomingBuffer;
var note = document.getElementById(domNode);
note.addEventListener("click", bufferFunctionName , false);
}
);
};
xhr.send();
};

</script>

CSS
<style>

#kickDrum {
background-color:orange;
position:absolute;
top:25%;
left:25%;
width: 200px;
height:200px;
border-radius:120px;
border-style:solid;
border-width:15px;
border-color:grey;
}

#snareDrum {
background-color:orange;
position:absolute;
top:25%;
left:50%;
width: 200px;
height:200px;
border-radius:120px;
border-style:solid;
border-width:15px;
border-color:grey;
}

</style>

关于flash - 浏览器中循环音频的最佳方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15289643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com