getAudioInfo method
Gets audio file information without conversion
Implementation
@override
Future<Map<String, dynamic>> getAudioInfo(String inputPath) async {
try {
// For web, we can get basic info using HTML Audio element
final audio = web.HTMLAudioElement();
final completer = Completer<Map<String, dynamic>>();
void onLoadedMetadata() {
final info = <String, dynamic>{
'duration':
(audio.duration * 1000).round(), // Convert to milliseconds
'format': inputPath.split('.').last.toLowerCase(),
'channels': 2, // HTML Audio API doesn't expose channel count
'sampleRate': 44100, // Default assumption for web
'bitRate': 128, // Default assumption
'fileSize': 0, // Not available from HTML Audio API
'platform': 'web',
'supported': true,
};
completer.complete(info);
}
void onError() {
completer.completeError('Failed to load audio file');
}
// Set up event listeners
audio.addEventListener('loadedmetadata', onLoadedMetadata.toJS);
audio.addEventListener('error', onError.toJS);
// Set source and load
audio.src = inputPath;
audio.load();
return await completer.future.timeout(
const Duration(seconds: 10),
onTimeout: () => throw TimeoutException('Audio loading timed out'),
);
} catch (e) {
throw Exception('Failed to get audio info on web: $e');
}
}