mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-15 16:17:58 +00:00
.load method returns a Promise
This commit is contained in:
parent
45eba82840
commit
3ca0eadafd
2 changed files with 12 additions and 3 deletions
|
@ -129,11 +129,10 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function(To
|
|||
* browser.
|
||||
* @param {function=} callback The function to invoke once
|
||||
* the sample is loaded.
|
||||
* @returns {Tone.Player} this
|
||||
* @returns {Promise}
|
||||
*/
|
||||
Tone.Player.prototype.load = function(url, callback){
|
||||
this._buffer.load(url, this._onload.bind(this, callback));
|
||||
return this;
|
||||
return this._buffer.load(url, this._onload.bind(this, callback));
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -141,6 +140,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function(To
|
|||
* @private
|
||||
*/
|
||||
Tone.Player.prototype._onload = function(callback){
|
||||
callback = this.defaultArg(callback, Tone.noOp);
|
||||
callback(this);
|
||||
if (this.autostart){
|
||||
this.start();
|
||||
|
|
|
@ -54,6 +54,15 @@ define(["helper/Basic", "Tone/source/Player", "helper/Offline",
|
|||
});
|
||||
});
|
||||
|
||||
it("returns a promise", function(done){
|
||||
var player = new Player();
|
||||
var promise = player.load("./audio/sine.wav");
|
||||
expect(promise).to.be.instanceof(Promise);
|
||||
promise.then(function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("can be created with an options object", function(){
|
||||
var player = new Player({
|
||||
"url" : "./audio/sine.wav",
|
||||
|
|
Loading…
Reference in a new issue