javascript - How do I call the start() & stop() methods in this to create functional audio controls? -


i have method audiobuffersourcenode holds audio file has been loaded.

on line 136 line 13 below start() , stop() methods being used on audio node other things, can't thing. how call these methods play , pause audio. don't know correct way call start() & stop() methods have buttons or divs play/ pause audio , how use methods have volume slider , mute button. how go doing it?

side note: told declaring variable 'audiobuffersourcenode' globally better practice, not sure how or meant or if has problem.

so on line 13 start() , stop() methods being used on audio node.

 _visualize: function(audiocontext, buffer) {     var audiobuffersourcenode = audiocontext.createbuffersource(),         analyser = audiocontext.createanalyser(),         = this;     //connect source analyser     audiobuffersourcenode.connect(analyser);     //connect analyser destination(the speaker), or won't hear sound     analyser.connect(audiocontext.destination);     //then assign buffer buffer source node     audiobuffersourcenode.buffer = buffer;     //play source     if (!audiobuffersourcenode.start) {         audiobuffersourcenode.start = audiobuffersourcenode.noteon //in old browsers use noteon method         audiobuffersourcenode.stop = audiobuffersourcenode.noteoff //in old browsers use noteon method     };     //stop previous sound if     if (this.animationid !== null) {         cancelanimationframe(this.animationid);     }     if (this.source !== null) {         this.source.stop(0);     }     audiobuffersourcenode.start(0);     this.status = 1;     this.source = audiobuffersourcenode;     audiobuffersourcenode.onended = function() {         that._audioend(that);     };     this._updateinfo('playing ' + this.filename, false);     this.info = 'playing ' + this.filename;     document.getelementbyid('filewrapper').style.opacity = 0.2;     this._drawspectrum(analyser);  }, 

full code:

https://jsfiddle.net/4hty6kak/1/

web audio api doesn't work on jsfiddle, here's live working demo:

http://wayou.github.io/html5_audio_visualizer/

do have simple solid solutions?


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -