插件record_mp3 FLUTTER缺少插件实现

rqmkfv5c  于 2022-12-19  发布在  Flutter
关注(0)|答案(1)|浏览(132)

当使用record_mp3录制音频时,会给予UnhandledException:MissingPluginException(找不到方法记录mp3的实现。
代码很简单,就像文档中说的那样:'

if (await hasPermission() ) {
  RecordMp3.instance.start(widget.path, (type) {
    // record fail callback
  });

  bool isRecording =  RecordMp3.instance.status == RecordStatus.RECORDING ? true : false;
  setState(() {
    _isRecording = isRecording;
    _recordDuration = 0;
  });

  _startTimer();
}

'

vxf3dgd4

vxf3dgd41#

我找到了解决的办法,
在android/app/src/Kotlin的MainActivity.kt文件中,您必须添加您使用过的插件,如本例所示,只需导入插件,然后将其放入MainActivity类中,如下所示:

import io.flutter.plugins.GeneratedPluginRegistrant
import com.plugin.record_mp3.RecordMp3Plugin
class MainActivity: FlutterActivity() {

override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    flutterEngine.getPlugins().add(RecordMp3Plugin())

  }
}

相关问题