Remove old silence tests, test via canPlayType().

This commit is contained in:
Michael Jumper
2012-10-23 19:05:32 -07:00
parent 564c58ca20
commit 2e681a1348
6 changed files with 22 additions and 25 deletions

View File

@@ -30,7 +30,7 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId> <artifactId>maven-war-plugin</artifactId>
<configuration> <configuration>
<!-- Filter webapp dir --> <!-- Filter webapp dir -->
<webResources> <webResources>
<resource> <resource>

View File

@@ -149,6 +149,12 @@
window.location.search.substring(1) window.location.search.substring(1)
+ "&width=" + window.innerWidth + "&width=" + window.innerWidth
+ "&height=" + window.innerHeight; + "&height=" + window.innerHeight;
// Add audio mimetypes to connect_string
GuacamoleUI.supportedAudio.forEach(function(mimetype) {
connect_string += "&audio=" + mimetype;
});
guac.connect(connect_string); guac.connect(connect_string);
} }

View File

@@ -61,8 +61,11 @@ var GuacamoleUI = {
}; };
// Supported mimetypes /**
GuacamoleUI.supportedAudio = {}; * Array of all supported audio mimetypes, populated when this script is
* loaded.
*/
GuacamoleUI.supportedAudio = [];
// Constant UI initialization and behavior // Constant UI initialization and behavior
(function() { (function() {
@@ -487,32 +490,20 @@ GuacamoleUI.supportedAudio = {};
GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px"; GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
}); });
function testAudio(url, mimetype) { // Build array of supported audio formats
[
'audio/ogg; codecs="vorbis"',
'audio/mpeg; codecs="mp3"',
'audio/wav'
].forEach(function(mimetype) {
// If browser says we can't play it, don't try
var audio = new Audio(); var audio = new Audio();
if (!audio.canPlayType(mimetype)) var support_level = audio.canPlayType(mimetype);
return;
// Otherwise, test if (support_level != "")
audio.src = url; GuacamoleUI.supportedAudio.push(mimetype);
// On error, explicitly unsupported });
audio.addEventListener("error", function() {
GuacamoleUI.supportedAudio[mimetype] = false;
});
// On successful play, explicitly supported
audio.addEventListener("ended", function() {
GuacamoleUI.supportedAudio[mimetype] = true;
});
audio.play();
}
testAudio("sounds/silence.mp3", "audio/mpeg");
testAudio("sounds/silence.ogg", "audio/ogg");
})(); })();