mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
parent
a730873ff1
commit
9e140a7605
2 changed files with 21 additions and 7 deletions
|
@ -19,16 +19,18 @@ define(["Tone/core/Tone", "Tone/source/Source"], function(Tone){
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._mediaStream = null;
|
this._mediaStream = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {LocalMediaStream}
|
* @type {LocalMediaStream}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._stream = null;
|
this._stream = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.constraints = {"audio" : true};
|
this._constraints = {"audio" : true};
|
||||||
|
|
||||||
//get the option
|
//get the option
|
||||||
var self = this;
|
var self = this;
|
||||||
|
@ -49,7 +51,7 @@ define(["Tone/core/Tone", "Tone/source/Source"], function(Tone){
|
||||||
Tone.Microphone.prototype.start = function(){
|
Tone.Microphone.prototype.start = function(){
|
||||||
if (this.state === Tone.Source.State.STOPPED){
|
if (this.state === Tone.Source.State.STOPPED){
|
||||||
this.state = Tone.Source.State.STARTED;
|
this.state = Tone.Source.State.STARTED;
|
||||||
navigator.getUserMedia(this.constraints,
|
navigator.getUserMedia(this._constraints,
|
||||||
this._onStream.bind(this), this._onStreamError.bind(this));
|
this._onStream.bind(this), this._onStreamError.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -90,10 +92,12 @@ define(["Tone/core/Tone", "Tone/source/Source"], function(Tone){
|
||||||
*/
|
*/
|
||||||
Tone.Microphone.prototype.dispose = function() {
|
Tone.Microphone.prototype.dispose = function() {
|
||||||
Tone.Source.prototype.dispose.call(this);
|
Tone.Source.prototype.dispose.call(this);
|
||||||
this._stream.disconnect();
|
if (this._mediaStream){
|
||||||
this._mediaStream.disconnect();
|
this._mediaStream.disconnect();
|
||||||
this._stream = null;
|
|
||||||
this._mediaStream = null;
|
this._mediaStream = null;
|
||||||
|
}
|
||||||
|
this._stream = null;
|
||||||
|
this._constraints = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
//polyfill
|
//polyfill
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
define(["chai", "Tone/source/Player", "Tone/core/Master", "Tone/source/Oscillator",
|
define(["chai", "Tone/source/Player", "Tone/core/Master", "Tone/source/Oscillator",
|
||||||
"Tone/component/Recorder", "Tone/source/Noise", "tests/Core", "Tone/source/PulseOscillator", "tests/Common",
|
"Tone/component/Recorder", "Tone/source/Noise", "tests/Core", "Tone/source/PulseOscillator", "tests/Common",
|
||||||
"Tone/source/PWMOscillator", "Tone/source/OmniOscillator"],
|
"Tone/source/PWMOscillator", "Tone/source/OmniOscillator", "Tone/source/Microphone"],
|
||||||
function(chai, Player, Master, Oscillator, Recorder, Noise, core, PulseOscillator, Test, PWMOscillator, OmniOscillator){
|
function(chai, Player, Master, Oscillator, Recorder, Noise, core, PulseOscillator, Test,
|
||||||
|
PWMOscillator, OmniOscillator, Microphone){
|
||||||
|
|
||||||
var expect = chai.expect;
|
var expect = chai.expect;
|
||||||
|
|
||||||
|
@ -617,4 +618,13 @@ function(chai, Player, Master, Oscillator, Recorder, Noise, core, PulseOscillato
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Tone.Microphone", function(){
|
||||||
|
this.timeout(maxTimeout);
|
||||||
|
|
||||||
|
it("can be created and disposed", function(){
|
||||||
|
var mic = new Microphone();
|
||||||
|
mic.dispose();
|
||||||
|
Test.wasDisposed(mic);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
Reference in a new issue