diff --git a/guacamole-common-js/src/main/resources/audio.js b/guacamole-common-js/src/main/resources/audio.js index 3cb0841a3..0bf708f34 100644 --- a/guacamole-common-js/src/main/resources/audio.js +++ b/guacamole-common-js/src/main/resources/audio.js @@ -111,6 +111,11 @@ Guacamole.AudioChannel = function() { }; +// Define context if available +if (window.webkitAudioContext) { + Guacamole.AudioChannel.context = new webkitAudioContext(); +} + /** * Abstract representation of an audio packet. * @@ -122,23 +127,76 @@ Guacamole.AudioChannel = function() { */ Guacamole.AudioChannel.Packet = function(mimetype, duration, data) { - // Build data URI - var data_uri = "data:" + mimetype + ";base64," + data; - - // Create audio element to house and play the data - var audio = new Audio(); - audio.src = data_uri; - /** * The duration of this packet, in milliseconds. */ this.duration = duration; - /** - * Plays the sound data contained by this packet immediately. - */ - this.play = function() { - audio.play(); - }; + // If audio API available, use it. + if (Guacamole.AudioChannel.context) { + + var readyBuffer = null; + + // By default, when decoding finishes, store buffer for future + // playback + var handleReady = function(buffer) { + readyBuffer = buffer; + }; + + // Convert to ArrayBuffer + var binary = window.atob(data); + var arrayBuffer = new ArrayBuffer(binary.length); + var bufferView = new Uint8Array(arrayBuffer); + + for (var i=0; i