@@ -44,16 +44,20 @@ function MicTest(test) {
4444 for ( var i = 0 ; i < this . inputChannelCount ; ++ i ) {
4545 this . collectedAudio [ i ] = [ ] ;
4646 }
47+ var AudioContext = window . AudioContext || window . webkitAudioContext ;
48+ this . audioContext = new AudioContext ( ) ;
4749}
4850
4951MicTest . prototype = {
5052 run : function ( ) {
51- if ( typeof audioContext === 'undefined' ) {
52- this . test . reportError ( 'WebAudio is not supported, test cannot run.' ) ;
53+ // Resuming as per new spec after user interaction.
54+ this . audioContext . resume ( ) . then ( function ( ) {
55+ doGetUserMedia ( this . constraints , this . gotStream . bind ( this ) )
56+ } . bind ( this ) )
57+ . catch ( function ( error ) {
58+ this . test . reportError ( 'WebAudio run failure: ' + error ) ;
5359 this . test . done ( ) ;
54- } else {
55- doGetUserMedia ( this . constraints , this . gotStream . bind ( this ) ) ;
56- }
60+ } . bind ( this ) ) ;
5761 } ,
5862
5963 gotStream : function ( stream ) {
@@ -77,11 +81,11 @@ MicTest.prototype = {
7781 } ,
7882
7983 createAudioBuffer : function ( ) {
80- this . audioSource = audioContext . createMediaStreamSource ( this . stream ) ;
81- this . scriptNode = audioContext . createScriptProcessor ( this . bufferSize ,
84+ this . audioSource = this . audioContext . createMediaStreamSource ( this . stream ) ;
85+ this . scriptNode = this . audioContext . createScriptProcessor ( this . bufferSize ,
8286 this . inputChannelCount , this . outputChannelCount ) ;
8387 this . audioSource . connect ( this . scriptNode ) ;
84- this . scriptNode . connect ( audioContext . destination ) ;
88+ this . scriptNode . connect ( this . audioContext . destination ) ;
8589 this . scriptNode . onaudioprocess = this . collectAudio . bind ( this ) ;
8690 this . stopCollectingAudio = setTimeoutWithProgressBar (
8791 this . onStopCollectingAudio . bind ( this ) , 5000 ) ;
@@ -124,7 +128,7 @@ MicTest.prototype = {
124128 onStopCollectingAudio : function ( ) {
125129 this . stream . getAudioTracks ( ) [ 0 ] . stop ( ) ;
126130 this . audioSource . disconnect ( this . scriptNode ) ;
127- this . scriptNode . disconnect ( audioContext . destination ) ;
131+ this . scriptNode . disconnect ( this . audioContext . destination ) ;
128132 this . analyzeAudio ( this . collectedAudio ) ;
129133 this . test . done ( ) ;
130134 } ,
0 commit comments