mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
test for file type support.
This commit is contained in:
parent
810ee8530e
commit
d0b18c5d09
1 changed files with 16 additions and 0 deletions
|
@ -351,5 +351,21 @@ define(["Tone/core/Tone", "Tone/core/Emitter"], function(Tone){
|
|||
return request;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks a url's extension to see if the current browser can play that file type.
|
||||
* @param {String} url The url/extension to test
|
||||
* @return {Boolean} If the file extension can be played
|
||||
* @static
|
||||
* @example
|
||||
* Tone.Buffer.supportsType("wav"); //returns true
|
||||
* Tone.Buffer.supportsType("path/to/file.wav"); //returns true
|
||||
*/
|
||||
Tone.Buffer.supportsType = function(url){
|
||||
var extension = url.split(".");
|
||||
extension = extension[extension.length - 1];
|
||||
var response = document.createElement("audio").canPlayType("audio/"+extension);
|
||||
return response !== "";
|
||||
};
|
||||
|
||||
return Tone.Buffer;
|
||||
});
|
Loading…
Reference in a new issue