init method

  1. @override
Future<void> init(
  1. String mainPath, {
  2. String accentedPath = '',
  3. int bpm = 120,
  4. int volume = 50,
  5. bool enableTickCallback = false,
  6. int timeSignature = 4,
  7. int sampleRate = 44100,
})
override

Implementation

@override
Future<void> init(
  String mainPath, {
  String accentedPath = '',
  int bpm = 120,
  int volume = 50,
  bool enableTickCallback = false,
  int timeSignature = 4,
  int sampleRate = 44100,
}) async {
  if (mainPath == '') {
    throw Exception('Main path cannot be empty');
  }
  if (volume > 100 || volume < 0) {
    throw Exception('Volume must be between 0 and 100');
  }
  if (bpm <= 0) {
    throw Exception('BPM must be greater than 0');
  }
  if (timeSignature < 0) {
    throw Exception('timeSignature must be greater than 0');
  }
  if (sampleRate <= 0) {
    throw Exception('sampleRate must be greater than 0');
  }
  Uint8List mainFileBytes = await loadFileBytes(mainPath);
  Uint8List accentedFileBytes = Uint8List.fromList([]);
  if (accentedPath != '') {
    accentedFileBytes = await loadFileBytes(accentedPath);
  }
  try {
    await methodChannel.invokeMethod<void>('init', {
      'mainFileBytes': mainFileBytes,
      'accentedFileBytes': accentedFileBytes,
      'bpm': bpm,
      'volume': volume / 100.0,
      'enableTickCallback': enableTickCallback,
      'timeSignature': timeSignature,
      'sampleRate': sampleRate,
    });
  } catch (e) {
    if (kDebugMode) {
      print(e);
    }
  }
}