在颤动中播放音频

play audio in flutter

我做了一个 flutter 演示,它在 Android、iphone、linux 桌面和 mac 桌面上运行良好,但在 windows 桌面上它给出了我的错误

[ERROR:c:\b\s\w\ir\cache\builder\src\flutter\lib\ui\ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method stop on channel xyz.luan/audioplayers)

谁能帮我解决这个错误?

在这个演示中,我使用 audioplayers 0.14.2 在 flutter 中播放本地音频文件。

这是我的代码:-

      void main() {
        debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
        runApp(new MaterialApp(home: new ExampleApp()));
      }

      class ExampleApp extends StatefulWidget {
        @override
        _ExampleAppState createState() => new _ExampleAppState();
      }

      class _ExampleAppState extends State<ExampleApp> {
        AudioPlayer advancedPlayer;
        AudioCache audioCache;

        @override
        void initState() {
          super.initState();
          initPlayer();
        }

        void initPlayer() {
          advancedPlayer = new AudioPlayer();
          audioCache = new AudioCache(fixedPlayer: advancedPlayer);
        }

        void playfirst() {
          audioCache.play('audio1.mp3');
        }

        void stop() {
          advancedPlayer.stop();
        }

        @override
        Widget build(BuildContext context) {
          return DefaultTabController(
            length: 1,
            child: Scaffold(
              appBar: AppBar(
                title: Text('Audio file demo'),
              ),
              body: Center(
                child: Column(
                  children: <Widget>[
                    ButtonTheme(
                        minWidth: 48.0,
                        child: RaisedButton(child: Text("play"), onPressed: playfirst)),
                    ButtonTheme(
                        minWidth: 48.0,
                        child: RaisedButton(child: Text("stop"), onPressed: stop))
                  ],
                ),
              )
            ),
          );
        }
      }

can any one help me to resolve this error?

解决该错误的唯一方法是为 Windows 编写该插件的实现;它告诉你插件丢失的原因是插件没有 Windows 支持(你可以知道是因为插件存储库中没有 windows 文件夹,或者 windows: 条目在 the pubspec.yaml).

its work fine in [...] linux desktop

这很奇怪,因为您使用的插件也不支持 Linux。

您目前不太可能找到支持 Windows 的插件,因为 the official documentation 目前说:

Note: Windows and Linux plugin APIs and tooling are not yet stable, so any plugin written now will need frequent updates for breaking changes. Because of this, publishing Windows and/or Linux plugins to pub.dev at this stage is strongly discouraged.