Permalink
Browse files

removed debug

  • Loading branch information...
1 parent 74d1600 commit c3e6f539a5b2266fd8929f24ce993fd9b2af5af1 @jeromeetienne committed Aug 2, 2012
Showing with 42 additions and 1 deletion.
  1. +42 −1 src/webaudio.core.js
View
@@ -50,13 +50,16 @@ WebAudio = function(){
// setup internal variable
this._muted = false;
this._volume = 1;
-
+
// setup the end of the node chain
// TODO later code the clipping detection from http://www.html5rocks.com/en/tutorials/webaudio/games/
this._gainNode = this._ctx.createGainNode();
this._compressor= this._ctx.createDynamicsCompressor();
this._gainNode.connect( this._compressor );
this._compressor.connect( this._ctx.destination );
+
+ // init page visibility
+ this._pageVisibilityCtor();
};
@@ -71,6 +74,7 @@ WebAudio.fn = WebAudio.prototype;
* destructor
*/
WebAudio.prototype.destroy = function(){
+ this._pageVisibilityDtor();
};
/**
@@ -114,6 +118,10 @@ WebAudio.prototype._entryNode = function(){
return this._gainNode;
}
+//////////////////////////////////////////////////////////////////////////////////
+// volume/mute //
+//////////////////////////////////////////////////////////////////////////////////
+
/**
* getter/setter on the volume
*/
@@ -146,3 +154,36 @@ WebAudio.prototype.toggleMute = function(){
if( this.mute() ) this.mute(false);
else this.mute(true);
}
+
+//////////////////////////////////////////////////////////////////////////////////
+// pageVisibility //
+//////////////////////////////////////////////////////////////////////////////////
+
+
+WebAudio.prototype._pageVisibilityCtor = function(){
+ // shim to handle browser vendor
+ this._pageVisibilityEventStr = (document.hidden !== undefined ? 'visibilitychange' :
+ (document.mozHidden !== undefined ? 'mozvisibilitychange' :
+ (document.msHidden !== undefined ? 'msvisibilitychange' :
+ (document.webkitHidden !== undefined ? 'webkitvisibilitychange' :
+ console.assert(false, "Page Visibility API unsupported")
+ ))));
+ this._pageVisibilityDocumentStr = (document.hidden !== undefined ? 'hidden' :
+ (document.mozHidden !== undefined ? 'mozHidden' :
+ (document.msHidden !== undefined ? 'msHidden' :
+ (document.webkitHidden !== undefined ? 'webkitHidden' :
+ console.assert(false, "Page Visibility API unsupported")
+ ))));
+ // event handler for visibilitychange event
+ this._$pageVisibilityCallback = function(){
+ var isHidden = document[this._pageVisibilityDocumentStr] ? true : false;
+ this.mute( isHidden ? true : false );
+ }.bind(this);
+ // bind the event itself
+ document.addEventListener(this._pageVisibilityEventStr, this._$pageVisibilityCallback, false);
+}
+
+WebAudio.prototype._pageVisibilityDtor = function(){
+ // unbind the event itself
+ document.removeEventListener(this._pageVisibilityEventStr, this._$pageVisibilityCallback, false);
+}

0 comments on commit c3e6f53

Please sign in to comment.