getAmplitudes method

  1. @override
Future<List<int>> getAmplitudes(
  1. String filePath,
  2. int samplesPerSecond
)
override

Implementation

@override
Future<List<int>> getAmplitudes(String filePath, int samplesPerSecond) async {
  final List<dynamic>? amplitudes =
      await methodChannel.invokeMethod<List<dynamic>>(
    'getAmplitudes',
    {
      'filePath': filePath,
      'samplesPerSecond': samplesPerSecond,
    },
  );
  if (amplitudes == null) {
    return <int>[];
  }
  return amplitudes.map<int>((dynamic amp) {
    if (amp is int) {
      return amp;
    }
    if (amp is double) {
      return (amp * 100).round().clamp(0, 100);
    }
    throw PlatformException(
      code: 'INVALID_RESULT',
      message: 'Unexpected amplitude value type: ${amp.runtimeType}',
    );
  }).toList();
}