javascript - Use renderedBuffer as HTML5 Audio tag -


so i've used webaudioapi create music code. i've used offlineaudiocontext create music , it's oncomplete event similar this:

function(e) {     var audioctx = new (window.audiocontext || window.webkitaudiocontext)();     var song = audioctx.createbuffersource();     song.buffer = e.renderedbuffer;     song.connect(audioctx.destination);     song.start(); } 

which plays sound. , works. instead store <audio> element, because it's easier play, loop, pause , stop, need reuse song.

is possible? i'm googling days, can't find how!

the idea use var song = new audio() , copy e.renderedbuffer it.

ok, found code floating around: http://codedbot.com/questions-/911767/web-audio-api-output . i've created copy here too: http://pastebin.com/re9a1pax .

i've managed use code create , store audio on fly, using function provided in link.

offaudioctx.oncomplete = function(e) {     var buffer   = e.renderedbuffer;     var uintwave = createwavefiledata(buffer);     var base64   = btoa(uint8tostring(uintwave));      songsarr.push(document.createelement('audio'))     songsarr[songsarr.length-1].src = "data:audio/wav;base64," + base64;     console.log("completed!"); }; 

it's not pretty, works. i'm leaving here in case finds easier way.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -