isFormatSupported method
Checks if the given audio format is supported for processing
inputPath
- Path to the audio file to check
Returns true if the format is supported, false otherwise.
Implementation
@override
Future<bool> isFormatSupported(String inputPath) async {
// Check file extension
final extension = inputPath.toLowerCase().split('.').last;
// Web browsers commonly support these formats
const supportedFormats = ['mp3', 'wav', 'ogg', 'webm', 'm4a', 'aac'];
if (!supportedFormats.contains(extension)) {
return false;
}
// Create a test audio element to check browser support
final audio = web.HTMLAudioElement();
switch (extension) {
case 'mp3':
return audio.canPlayType('audio/mpeg').isNotEmpty;
case 'wav':
return audio.canPlayType('audio/wav').isNotEmpty;
case 'ogg':
return audio.canPlayType('audio/ogg').isNotEmpty;
case 'webm':
return audio.canPlayType('audio/webm').isNotEmpty;
case 'm4a':
case 'aac':
return audio.canPlayType('audio/mp4').isNotEmpty;
default:
return false;
}
}