getDurationForFile method
Implementation
Future<Duration?> getDurationForFile(String filePath) async {
final tempPlayer = AudioPlayer();
try {
await tempPlayer.setSource(DeviceFileSource(filePath));
final duration = await tempPlayer.getDuration();
return duration;
} catch (e) {
print('Error getting duration for $filePath: $e');
return null;
} finally {
await tempPlayer.dispose();
}
}