1

我的大部分后台代码都以 结尾MissingPluginException,我不知道为什么,但我按照它所说的那样实现了一切;我尝试了所有可能的在线解决方案,但没有任何效果;现在,当我尝试使用 home_widget 插件从 android-home-widget 播放音频时, 我正面临着 audio_service插件

最少的代码:

AudioPlayerTask audioPlayerTask;

void homeWidgetBackgroundCallback(Uri data) async {
    WidgetsFlutterBinding.ensureInitialized();
    if(audioPlayerTask == null) {
      audioPlayerTask = AudioPlayerTask();
      await AudioServiceBackground.run(() => audioPlayerTask);
    }
    AudioServiceBackground.state.playing ? audioPlayerTask.onPause() : audioPlayerTask.onPlay();
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
  HomeWidget.registerBackgroundCallback(homeWidgetBackgroundCallback);
}

错误信息:

2021-08-12 10:49:25.444 25804-25849/com.******* E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: MissingPluginException(No implementation found for method ready on channel ryanheise.com/audioServiceBackground)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
    <asynchronous suspension>
    #1      AudioServiceBackground.run (package:audio_service/audio_service.dart:1271:24)
    <asynchronous suspension>
    #2      homeWidgetBackgroundCallback (package:*******/main.dart:72:7)
    <asynchronous suspension>

颤振医生:

[√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1151], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] IntelliJ IDEA Ultimate Edition (version 2020.1)
[√] VS Code, 64-bit edition (version 1.58.2)
[√] Connected device (3 available)

• No issues found!

出现此错误的插件最多的是path_provider插件,它永远不会在后台运行;

有什么建议吗?

编辑

github:https ://github.com/ryanheise/audio_service/issues/789

4

2 回答 2

0

这是iOS还是Android?如果是 iOS,您必须注册要使用的插件才能与 HomeWidget 插件通信。这取自 Home_Widget 页面 - 在 flutter_workmanager 的情况下,这通过添加:

WorkmanagerPlugin.setPluginRegistrantCallback { registry in
    GeneratedPluginRegistrant.register(with: registry)
}

到 AppDelegate.swift

于 2021-09-22T07:08:57.057 回答
0

只需终止正在运行的进程,然后从头开始运行应用程序。

于 2021-08-19T12:14:18.270 回答