mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
GUAC-1354: Use Guacamole.AudioPlayer.getSupportedTypes() to query available audio mimetypes within webapp.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Glyptodon LLC
|
||||
* Copyright (C) 2015 Glyptodon LLC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -31,82 +31,11 @@ angular.module('client').factory('guacAudio', [function guacAudio() {
|
||||
return new (function() {
|
||||
|
||||
/**
|
||||
* Array of codecs to test.
|
||||
* Array of all supported audio mimetypes.
|
||||
*
|
||||
* @type String[]
|
||||
*/
|
||||
var codecs = [
|
||||
'audio/ogg; codecs="vorbis"',
|
||||
'audio/mp4; codecs="mp4a.40.5"',
|
||||
'audio/mpeg; codecs="mp3"',
|
||||
'audio/webm; codecs="vorbis"',
|
||||
'audio/wav; codecs=1'
|
||||
];
|
||||
|
||||
/**
|
||||
* Array of all codecs that are reported as "probably" supported.
|
||||
*
|
||||
* @type String[]
|
||||
*/
|
||||
var probably_supported = [];
|
||||
|
||||
/**
|
||||
* Array of all codecs that are reported as "maybe" supported.
|
||||
*
|
||||
* @type String[]
|
||||
*/
|
||||
var maybe_supported = [];
|
||||
|
||||
/**
|
||||
* Internal audio element for the sake of testing codec support. If
|
||||
* audio is explicitly not supported by the browser, this will instead
|
||||
* be null.
|
||||
*
|
||||
* @type Audio
|
||||
*/
|
||||
var audio = null;
|
||||
|
||||
// Attempt to create audio element
|
||||
try {
|
||||
audio = new Audio();
|
||||
}
|
||||
catch (e) {
|
||||
// If creation fails, allow audio to remain null
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of all supported audio mimetypes, ordered by liklihood of
|
||||
* working.
|
||||
*/
|
||||
this.supported = [];
|
||||
|
||||
// Build array of supported audio formats (if audio supported at all)
|
||||
if (audio) {
|
||||
codecs.forEach(function(mimetype) {
|
||||
|
||||
var support_level = audio.canPlayType(mimetype);
|
||||
|
||||
// Trim semicolon and trailer
|
||||
var semicolon = mimetype.indexOf(";");
|
||||
if (semicolon !== -1)
|
||||
mimetype = mimetype.substring(0, semicolon);
|
||||
|
||||
// Partition by probably/maybe
|
||||
if (support_level === "probably")
|
||||
probably_supported.push(mimetype);
|
||||
else if (support_level === "maybe")
|
||||
maybe_supported.push(mimetype);
|
||||
|
||||
});
|
||||
|
||||
// Add probably supported types first
|
||||
Array.prototype.push.apply(
|
||||
this.supported, probably_supported);
|
||||
|
||||
// Prioritize "maybe" supported types second
|
||||
Array.prototype.push.apply(
|
||||
this.supported, maybe_supported);
|
||||
}
|
||||
this.supported = Guacamole.AudioPlayer.getSupportedTypes();
|
||||
|
||||
})();
|
||||
|
||||
|
Reference in New Issue
Block a user