一段时间后,我想关闭 audio_service在 android_alarm_manager 的背景中插入。我怎么解决这个问题?
当我尝试这样做时,我收到以下错误。
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method stop on channel ryanheise.com/audioService)
我的代码如下。
action.dart
FlatButton(
onPressed: () async {
await AndroidAlarmManager.oneShot(Duration(minutes: _minute.floor().toInt()), 0, backgroundCallback);
Navigator.pop(context);
},
child: Text(S.of(context).set),
)
main.dart
void backgroundCallback() async {
AudioService.connect();
AudioService.stop();
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
init();
await sl<DotEnv>().load('.env');
//get theme
bool _isDarkTheme = await sl<SharedPreferenceHelper>().isDarkTheme() ?? false;
if (Platform.isAndroid) {
AndroidAlarmManager.initialize();
}
runApp(MainApp());
}
Flutter 和 Dart 版本:
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18362.720], locale tr-TR)
• Flutter version 1.12.13+hotfix.9 at D:\flutter
• Framework revision f139b11009 (11 days ago), 2020-03-30 13:57:30 -0700
• Engine revision af51afceb8
• Dart version 2.7.2
最佳答案
您的想法是正确的,尽管您必须等到它使用“await”实际连接:
await AudioService.connect();
AudioService.stop();
为此,您还需要升级到更改日志中提到的 0.9.0 或更高版本:关于flutter - 一段时间后,我想用android_alarm_manager插件在后台关闭audio_service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61168444/