颤抖地播放音频

时间:2020-04-02 10:34:00

标签: windows flutter dart desktop-application flutter-dependencies

我做了一个演示,使它在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来快速播放本地音频文件。

这是我的代码:-

      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))
                  ],
                ),
              )
            ),
          );
        }
      }

1 个答案:

答案 0 :(得分:1)

有人可以帮助我解决此错误吗?

解决该错误的唯一方法是为Windows编写该插件的实现。告诉您缺少该插件的原因是该插件不支持Windows(您可以知道这是因为插件存储库中没有windows文件夹,或者{{3 }}。

它在[...] linux桌面上正常工作

令人惊讶的是,考虑到您使用的插件也不支持Linux。

鉴于the pubspec.yaml当前表示:

,目前不太可能找到支持Windows的插件。

注意:Windows和Linux插件API和工具尚不稳定,因此,现在编写的任何插件都需要经常更新以打破更改。因此,强烈建议不要在此阶段将Windows和/或Linux插件发布到pub.dev。

相关问题