admin管理员组文章数量:1416335
One direction of this exchange is possible - I know you can use the source of an <audio>
element as a means of getting audio for use with the Web Audio API via createElementSourceNode()
. Is it possible to do the opposite, where an AudioBufferSourceNode
is used as the source for an <audio>
element?
I'm pretty sure this is impossible, but I've been looking through npm for standard-looking, no-frills recreations of default browser audio element playback controls intended for use with AudioBuffers
and I'm not finding anything.
One direction of this exchange is possible - I know you can use the source of an <audio>
element as a means of getting audio for use with the Web Audio API via createElementSourceNode()
. Is it possible to do the opposite, where an AudioBufferSourceNode
is used as the source for an <audio>
element?
I'm pretty sure this is impossible, but I've been looking through npm for standard-looking, no-frills recreations of default browser audio element playback controls intended for use with AudioBuffers
and I'm not finding anything.
- You mean in node.js? web-audio-api is intended for browsers so are HTMLAudioElements. – Kaiido Commented Aug 1, 2019 at 6:37
- Sorry - I'm using node.js with babel to bundle everything, probably should get rid of that tag. This is all happening on the browser. – Tinstar Commented Aug 1, 2019 at 6:41
- Why do you need this? After all, if you have an AudioBufferSourceNode, you have an AudioContext, and you can plug the node into the AudioContext's output and get sound out. – AKX Commented Aug 1, 2019 at 6:42
-
Most of the time I'm just playing segments of a large audiosprited file, but if the user wants to view more info for an object, I want to give them the ability to play just that object's audio, with standard audio controls. I'd mute everything else in the background. I don't need it to be in an
<audio>
tag, I'm just having a hard time finding a library that emulates those controls outside of the<audio>
tag. – Tinstar Commented Aug 1, 2019 at 6:45
1 Answer
Reset to default 7You can connect your AudioBufferSourceNode to a MediaStreamDestination node and then feed an HTMLAudioElement srcObject
with the .stream
property of this node:
start.onclick = e => {
const audioCtx = new AudioContext();
fetch("https://dl.dropboxusercontent./s/1cdwpm3gca9mlo0/kick.mp3")
.then(resp => resp.arrayBuffer())
.then(buf => audioCtx.decodeAudioData(buf))
.then(audioBuffer => {
const source = audioCtx.createBufferSource();
source.buffer = audioBuffer;
source.playbackRate.value = 0.1;
source.loop = true;
source.start(0);
const streamNode = audioCtx.createMediaStreamDestination();
source.connect(streamNode);
const audioElem = new Audio();
audioElem.controls = true;
document.body.appendChild(audioElem);
audioElem.srcObject = streamNode.stream;
})
.catch(console.error);
}
<button id="start">start</button>
本文标签: javascriptMake AudioBufferSourceNode the audio source of an ltaudiogt tagStack Overflow
版权声明:本文标题:javascript - Make AudioBufferSourceNode the audio source of an <audio> tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744717545a2621494.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论