WhatsApp
var MobilePlay = function () { /** @type {MobilePlay} */ var self = this; /** @type {null} */ this.source = null; /** @type {AudioContext|webkitAudioContext|null} */ this.context = null; /** * @param {String} file * @returns {void} */ var loadFile = function (file) { var soundXhr = new XMLHttpRequest(); soundXhr.open('GET', file); soundXhr.responseType = 'arraybuffer'; soundXhr.addEventListener('load', function (r) { self.context.decodeAudioData( soundXhr.response, function (buffer) { self.source.buffer = buffer; self.source.connect(self.context.destination); self.source.loop = false; }); self.play(); }); soundXhr.send(); }; /** * @returns {void} */ this.play = function () { this.source.start(0); }; /** * @param {String} file * @returns {void} */ this.init = function (file) { this.context = new (window.AudioContext || window.webkitAudioContext)(); this.source = this.context.createBufferSource(); loadFile(file); }; }; (new MobilePlay()).init('audio.mp3');