loadAssetAudioFile method

Future<int?> loadAssetAudioFile(
  1. String asset
)

Implementation

Future<int?> loadAssetAudioFile(String asset) async {
  const channel =
      BasicMessageChannel<dynamic>('com.wangyng.better_sound_effect.loadAudioFile', StandardMessageCodec());
  final Map<String, dynamic> requestMap = {"asset": asset};
  final reply = await channel.send(requestMap);

  if (!(reply is Map)) {
    _throwChannelException();
  }

  Map<String, dynamic> replyMap = Map<String, dynamic>.from(reply);
  if (replyMap['error'] != null) {
    final HashMap<String, dynamic> error = HashMap.from(replyMap['error']);
    _throwException(error);
  } else {
    final result = replyMap["result"];
    final soundId = result["soundId"];
    return soundId is String ? int.parse(soundId) : soundId.toInt();
  }
}