handled audio playback with aurora library

This commit is contained in:
Blue 2018-12-22 00:21:12 +03:00 committed by Gitea
parent 85a14b5101
commit 7fdcb657a4
13 changed files with 11711 additions and 41 deletions

View file

@ -2,6 +2,7 @@
var File = require("./file");
var Vocabulary = require("../../wType/vocabulary");
var Vector = require("../../wType/vector");
var Uint64 = require("../../wType/uint64");
var Audio = File.inherit({
@ -12,10 +13,15 @@ var Audio = File.inherit({
this._loadedFrames = 0;
this._totalFrames = 0;
this._waitingForFrames = false;
this._portions = [];
this._frames = new Vector();
this.addHandler("responseFrames");
},
destructor: function() {
this._frames.destructor();
File.fn.destructor.call(this);
},
hasMore: function() {
return this._totalFrames > this._loadedFrames;
},
@ -37,12 +43,25 @@ var Audio = File.inherit({
var success = data.at("result").valueOf();
if (success === 0) {
var amount = data.at("amount").valueOf();
var blob = data.at("data").clone();
var frames = data.at("frames");
var amount = frames.length();
var buffer = new ArrayBuffer(0);
for (var i = 0; i < amount; ++i) {
var blob = frames.at(i).clone();
this._frames.push(blob);
var frame = blob.valueOf();
var newArr = new Uint8Array(buffer.byteLength + frame.byteLength);
newArr.set(new Uint8Array(buffer), 0);
newArr.set(new Uint8Array(frame), buffer.byteLength);
buffer = newArr.buffer;
}
this._loadedFrames += amount;
this._waitingForFrames = false;
this._portions.push(blob);
this.trigger("newFrames", blob);
this.trigger("newFrames", buffer);
}
}
},