我想在后台录制音频,但当我的前台服务启动时,我的录音机控制器不断收到错误,我正在使用 audio_waveforms 作为我的录音机,这是包 https://pub.dev/packages/audio_waveforms 对于我正在使用的后台服务:https://pub.dev/packages/flutter_foreground_task/versions/4.0.1
this is the error i keep getting:
E/flutter (30659): #1 MethodChannel._invokeMethod
platform_channel.dart:315
E/flutter (30659): <asynchronous suspension>
E/flutter (30659): #2 AudioWaveformsInterface.checkPermission
audio_waveforms_interface.dart:89
E/flutter (30659): <asynchronous suspension>
E/flutter (30659): #3 RecorderController.checkPermission
recorder_controller.dart:249
E/flutter (30659): <asynchronous suspension>
E/flutter (30659): #4 RecorderController.record
这是我的代码
` class MyTaskHandler extends TaskHandler {
SendPort? _sendPort;
int _eventCount = 0;
@override
Future<void> onStart(DateTime timestamp, SendPort? sendPort) async {
_sendPort = sendPort;
mic();
// You can use the getData function to get the stored data.
final customData =
await FlutterForegroundTask.getData<String>(key: 'customData');
print('customData: $customData');
}
void mic() {
RecorderController recorderController = RecorderController();
recorderController.record(path: path2);
}
@override
Future<void> onEvent(DateTime timestamp, SendPort? sendPort) async {
FlutterForegroundTask.updateService(
notificationTitle: 'SpakBit',
notificationText: 'Recording',
// callback: () {
// bplay().getDir();
// bplay().startOrStopRecording();
// });
);
// Send data to the main isolate.
sendPort?.send(_eventCount);
_eventCount++;
}
@override
Future<void> onDestroy(DateTime timestamp, SendPort? sendPort) async {
// You can use the clearAllData function to clear all the stored data.
await FlutterForegroundTask.clearAllData();
}
@override
void onButtonPressed(String id) {
// Called when the notification button on the Android platform is pressed.
print('onButtonPressed >> $id');
}
@override
void onNotificationPressed() {
// Called when the notification itself on the Android platform is pressed.
// bplay(recorderController).getDir();
// "android.permission.SYSTEM_ALERT_WINDOW" permission must be granted for
// this function to be called.
// Note that the app will only route to "/resume-route" when it is exited so
// it will usually be necessary to send a message through the send port to
// signal it to restore state when the app is already started.
FlutterForegroundTask.launchApp("/");
_sendPort?.send('onNotificationPressed');
}
}
`