SHARE
TWEET

Untitled

a guest Jun 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. _play = (url, index) => {
  2.     this._getData(url);
  3.     this.source.start(index)
  4. }
  5.      
  6. _getData(url) {
  7.     this.source = this.audioContext.createBufferSource();
  8.     var request = new XMLHttpRequest();
  9.  
  10.     request.open('GET', url, true);
  11.  
  12.     request.responseType = 'arraybuffer';
  13.  
  14.  
  15.     request.onload = () => {
  16.         var audioData = request.response;
  17.         console.log(this.audioContext)
  18.         this.audioContext.decodeAudioData(audioData, buffer => {
  19.         this.source.buffer = buffer;
  20.         this.source.connect(this.audioContext.destination);
  21.     },
  22.  
  23.         function(e){ console.log("Error with decoding audio data" + e.err); });
  24.  
  25.     }
  26.  
  27.     request.send();
  28. }
  29.      
  30. this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top