getSupportedFormats
Get every file extension this browser can play, out of the formats soundhub knows. Handy for a diagnostics screen or a bug report.
getSupportedFormats(): string[];
Parameters
This method takes no parameters.
Returns
string[]: the supported extensions in lower case and without a dot, such as ['mp3', 'mpeg', 'opus', ...]. The list is empty when there is no document to ask, as in server-side rendering.
Example
import { SoundHub } from 'soundhub';
// Static: works before a hub exists
console.log(SoundHub.getSupportedFormats());
const soundHub = new SoundHub();
const formats = soundHub.getSupportedFormats();
if (!formats.includes('opus')) {
console.warn('No Opus support, falling back to mp3');
}
Good to know
- There is a static
SoundHub.getSupportedFormats()as well as the instance method. Both give the same list. - It runs
canPlayover the known extensions:mp3,mpeg,opus,ogg,oga,wav,aac,caf,m4a,m4b,mp4,weba,webm,flacanddolby. They come back in that order. - "Maybe" from the browser's
canPlayTypecounts as supported. - Added in 6.2.0.