var LoadedAudio = require('./loaded-audio');

var AudioManager = function() {
  var AudioContext = window.AudioContext || window.webkitAudioContext;

  this.ctx = new AudioContext();
  this.masterGain = this.ctx.createGain();
  this._volume = 1;
  this.isMuted = false;

  var iOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
  if (iOS) {
    this._enableiOS();
  }
};

AudioManager.prototype._enableiOS = function() {
  var self = this;

  var touch = function() {
    var buffer = self.ctx.createBuffer(1, 1, 22050);
    var source = self.ctx.createBufferSource();
    source.buffer = buffer;
    source.connect(self.ctx.destination);
    source.start(0);

    window.removeEventListener('touchstart', touch, false);
  };

  window.addEventListener('touchstart', touch, false);
};

AudioManager.prototype.mute = function() {
  this.isMuted = true;
  this._updateMute();
};

AudioManager.prototype.unmute = function() {
  this.isMuted = false;
  this._updateMute();
};

AudioManager.prototype.toggleMute = function() {
  this.isMuted = !this.isMuted;
  this._updateMute();
};

AudioManager.prototype._updateMute = function() {
  this.masterGain.gain.value = this.isMuted ? 0 : this._volume;
};

AudioManager.prototype.setVolume = function(volume) {
  this._volume = volume;
  this.masterGain.gain.value = volume;
};

AudioManager.prototype.load = function(url, callback) {
  var self = this;

  var request = new XMLHttpRequest();
  request.open('GET', url, true);
  request.responseType = 'arraybuffer';
  request.onload = function() {
    self.decodeAudioData(request.response, function(source) {
      callback(source);
    });
  };
  request.send();
};

AudioManager.prototype.decodeAudioData = function(data, callback) {
  var self = this;

  this.ctx.decodeAudioData(data, function(result) {
    var audio = new LoadedAudio(self.ctx, result, self.masterGain);

    callback(audio);
  });
};

module.exports = AudioManager;

@@ -150,16 +150,17 @@
 %0A  this.
+_
 ctx = ne
@@ -176,32 +176,33 @@
 ntext();%0A  this.
+_
 masterGain = thi
@@ -199,24 +199,25 @@
 Gain = this.
+_
 ctx.createGa
@@ -482,32 +482,33 @@
 r buffer = self.
+_
 ctx.createBuffer
@@ -540,24 +540,25 @@
 urce = self.
+_
 ctx.createBu
@@ -623,16 +623,17 @@
 ct(self.
+_
 ctx.dest
@@ -1132,32 +1132,33 @@
 tion() %7B%0A  this.
+_
 masterGain.gain.
@@ -1288,16 +1288,17 @@
 %0A  this.
+_
 masterGa
@@ -1761,16 +1761,17 @@
 %0A  this.
+_
 ctx.deco
@@ -1844,16 +1844,17 @@
 io(self.
+_
 ctx, res
@@ -1863,16 +1863,17 @@
 t, self.
+_
 masterGa

make some properties in manager private