[SOLVED] Use Base 64 Audio as asset

Thank you for your replay @Leonidas !

That’s exactly what my next thought was :slight_smile:

I was able to get it to work now!

    var base64 = "data:audio/mpeg;base64,SUQzBA.....";
    var options = {retry: false};
    options.responseType = "arraybuffer";
    
    var audioContext = new AudioContext();
    
    pc.http.get(base64, options, function(err, response) {
        if (err) {
          console.log(err);
          return;
        }
        audioContext.decodeAudioData(response, function(buffer) {
             var soundComp = new pc.Sound(audioBuffer);
             asset = new pc.Asset("myAudioAsset-"+this.audioFileCount, "audio", null, base64);
             asset.resource = soundComp;
             asset.loaded = true;
             this.app.assets.add(asset);
        }.bind(this),
        function(e) {
            console.error("error decoding audio data" + e.err);
        }.bind(this));
    }.bind(this));

I can then add the a Slot with that Asset and play it!

1 Like