babylon.audioengine.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var BABYLON;
  2. (function (BABYLON) {
  3. var AudioEngine = (function () {
  4. function AudioEngine() {
  5. this.audioContext = null;
  6. this.canUseWebAudio = false;
  7. try {
  8. if (typeof AudioContext !== 'undefined') {
  9. this.audioContext = new AudioContext();
  10. this.canUseWebAudio = true;
  11. } else if (typeof webkitAudioContext !== 'undefined') {
  12. this.audioContext = new webkitAudioContext();
  13. this.canUseWebAudio = true;
  14. }
  15. } catch (e) {
  16. this.canUseWebAudio = false;
  17. }
  18. // create a global volume gain node
  19. if (this.canUseWebAudio) {
  20. this.masterGain = this.audioContext.createGain();
  21. this.masterGain.gain.value = 1;
  22. this.masterGain.connect(this.audioContext.destination);
  23. }
  24. }
  25. AudioEngine.prototype.getGlobalVolume = function () {
  26. if (this.canUseWebAudio) {
  27. return this.masterGain.gain.value;
  28. } else {
  29. return -1;
  30. }
  31. };
  32. AudioEngine.prototype.setGlobalVolume = function (newVolume) {
  33. if (this.canUseWebAudio) {
  34. this.masterGain.gain.value = newVolume;
  35. }
  36. };
  37. return AudioEngine;
  38. })();
  39. BABYLON.AudioEngine = AudioEngine;
  40. })(BABYLON || (BABYLON = {}));
  41. //# sourceMappingURL=babylon.audioengine.js.map