Advertisement
Guest User

Sound Player Code

a guest
Nov 17th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var SoundPlayer;
  2. window.Host && window.Host.Sound ? (Host.Log("Using SoundPlayer!"), SoundPlayer = function(t) {
  3.     function e(t, e) {
  4.         return r[t] = new i(t, e)
  5.     }
  6.  
  7.     function i(e, i) {
  8.         var r = this;
  9.         r.playing = !1;
  10.         var o = i;
  11.         this.resetGain = function() {
  12.             this.setGain(i)
  13.         }, this.setGain = function(t) {
  14.             o = t, Host.Sound.SetVolume(e, t)
  15.         }, this.play = function(i, a) {
  16.             function s() {
  17.                 Host.Sound.Play(e, e, a, o, t)
  18.             }
  19.             n.muted || t && r.playing || (r.playing = !0, i ? setTimeout(s, 1e3 * i) : s())
  20.         }, this.stop = function(t) {
  21.             r.playing = !1, Host.Sound.Stop(e)
  22.         }
  23.     }
  24.     t = t ? !0 : !1;
  25.     var r = [],
  26.         n = this;
  27.     this.muted = !1, this.setMuted = function(t) {
  28.         n.muted = t
  29.     }, this.get = function(i, n) {
  30.         return Host.Sound.Preload(i, i, t), r[i] || e(i, n)
  31.     }
  32. }) : SoundPlayer = function(t) {
  33.     function e() {
  34.         h = !0, s.length && s.shift().send()
  35.     }
  36.  
  37.     function i(i, r) {
  38.         function a(t, e) {
  39.             if (!o.muted && d.loaded) {
  40.                 p = {
  41.                     stop: function() {}
  42.                 };
  43.                 try {
  44.                     d.playing = !0, p = n.createBufferSource(), p.buffer = l, p.loop = e || !1, d.resetGain(), p.connect(c), c.connect(n.destination), p.start(n.currentTime + (t || 0))
  45.                 } catch (i) {}
  46.                 return p
  47.             }
  48.         }
  49.         var l, d = this;
  50.         d.targetGain = r, d.loaded = !1, d.playing = !1;
  51.         var c = {
  52.             gain: {
  53.                 value: 0
  54.             }
  55.         };
  56.         if (n) {
  57.             var u = new XMLHttpRequest;
  58.             u.open("GET", vpath + i, !0), u.responseType = "arraybuffer", u.onload = function() {
  59.                 e(), n.decodeAudioData(u.response, function(t) {
  60.                     l = t, d.loaded = !0
  61.                 })
  62.             }, s.push(u), h || (e(), t || e()), c = n.createGain ? n.createGain() : {
  63.                 gain: {
  64.                     value: 1
  65.                 }
  66.             }
  67.         }
  68.         this.gain = c.gain, this.setGain = function(t) {
  69.             this.gain.value = t
  70.         }, this.resetGain = function() {
  71.             this.gain.value = r
  72.         };
  73.         var p = void 0;
  74.         this.play = function(e, i) {
  75.             if (d.loaded) {
  76.                 if (t) {
  77.                     if (d.playing) return
  78.                 } else d.stop(0);
  79.                 a(e, i)
  80.             }
  81.         }, this.stop = function(t) {
  82.             if (p && d.playing) try {
  83.                 p.stop(t)
  84.             } catch (e) {}
  85.             d.playing = !1
  86.         }
  87.     }
  88.  
  89.     function r(t, e) {
  90.         return a[t] = new i(t, e)
  91.     }
  92.     var n, o = this;
  93.     (window.AudioContext || window.webkitAudioContext) && (SoundPlayer.context = n = SoundPlayer.context || new(window.AudioContext || window.webkitAudioContext));
  94.     var a = [];
  95.     this.muted = !1, this.setMuted = function(t) {
  96.         o.muted = t
  97.     }, this.get = function(t, e) {
  98.         return a[t] || r(t, e)
  99.     };
  100.     var s = [],
  101.         h = !1;
  102.     this.currentTrack = null
  103. }, SoundPlayer.unblocked = !1, window.Sound = new SoundPlayer, window.Music = new SoundPlayer(!0), window.backgroundMusic = null, window.clickSound = null, window.remoteConfig = {};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement