Flutter aduioplayers MissingPluginException(在频道xyz.luan / audioplayers上找不到方法startHeadlessService的实现)

时间:2019-11-22 01:41:18

标签: android flutter dart

我从Firestore流式传输数据,并将其转到要用audioplayers收听的url列表,但是当我打开屏幕时出现错误

这里是我的代码

//example Stream
StreamBuilder(
  stream: mystreamexample...,
  builder: (_, data) => ListView.builder(
    itemCount: data.length,
    itemBuilder: (BuildContext context, int index) {
      return AudioW(data);
    },
  ),
);


class AudioW extends StatefulWidget {
  final String time, url, name;

  AudioW ({
    Key key,
    this.time,
    this.url,
    this.name,
  }) : super(key: key);

  @override
  _AudioWState createState() => _AudioWState ();
}

class _AudioWState extends State<AudioW> {
  AudioPlayer _audioPlayer;
  String _duration = '00:00:00';
  bool _isPlaying = false;

  // _AudioBubbleState() {}

  @override
  void initState() {
    super.initState();
    _audioPlayer = AudioPlayer();
  }

  @override
  void dispose() {
    _audioPlayer.dispose();
    super.dispose();
  }

  _play(String url) async {
    await _audioPlayer.play(url);
    setState(() {
      _isPlaying = true;
    });
  }

  _pause() async {
    await _audioPlayer.pause();
    setState(() {
      _isPlaying = false;
    });
  }

  _stop() async {
    await _audioPlayer.stop();
    setState(() {
      _isPlaying = false;
      _duration = '00:00:00';
    });
  }

  _resume() async {
    await _audioPlayer.resume();
    setState(() {
      _isPlaying = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
      child: Column(
        children: <Widget>[
          Material(
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(
                10.0,
              ),
              side: BorderSide(
                color: primaryColor(context),
                width: .5,
              ),
            ),
            child: FittedBox(
              child: Row(
                children: <Widget>[
                  IconButton(
                    onPressed: () => _isPlaying ? _pause() : _play(widget.url),
                    icon: Icon(
                      _isPlaying ? Icons.pause : Icons.play_arrow,
                    ),
                  ),
                  Column(
                    children: <Widget>[
                      Container(
                        width: 100,
                        child: Text(
                          widget.name,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      Text(_duration),
                    ],
                  ),
                  IconButton(
                    icon: Icon(Icons.stop),
                    onPressed: _stop,
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}

这是我的错误

E/flutter (20575): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method startHeadlessService on channel xyz.luan/audioplayers)
[38;5;244mE/flutter (20575): #0      MethodChannel.invokeMethod[39;49m
E/flutter (20575): <asynchronous suspension>
[38;5;248mE/flutter (20575): #1      AudioPlayer._invokeMethod[39;49m
[38;5;248mE/flutter (20575): #2      new AudioPlayer[39;49m
[38;5;248mE/flutter (20575): #3      _AudioBubbleState.initState[39;49m
[38;5;244mE/flutter (20575): #4      StatefulElement._firstBuild[39;49m
[38;5;244mE/flutter (20575): #5      ComponentElement.mount[39;49m
[38;5;244mE/flutter (20575): #6      Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #7      Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #8      SingleChildRenderObjectElement.mount[39;49m
[38;5;244mE/flutter (20575): #9      Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #10     Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #11     SingleChildRenderObjectElement.mount[39;49m
[38;5;244mE/flutter (20575): #12     Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #13     Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #14     ComponentElement.performRebuild[39;49m
[38;5;244mE/flutter (20575): #15     Element.rebuild[39;49m
[38;5;244mE/flutter (20575): #16     ComponentElement._firstBuild[39;49m
[38;5;244mE/flutter (20575): #17     ComponentElement.mount[39;49m
[38;5;244mE/flutter (20575): #18     Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #19     Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #20     ComponentElement.performRebuild[39;49m
[38;5;244mE/flutter (20575): #21     Element.rebuild[39;49m
[38;5;244mE/flutter (20575): #22     ComponentElement._firstBuild[39;49m
[38;5;244mE/flutter (20575): #23     ComponentElement.mount[39;49m
[38;5;244mE/flutter (20575): #24     ParentDataElement.mount[39;49m
[38;5;244mE/flutter (20575): #25     Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #26     Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #27     ComponentElement.performRebuild[39;49m
[38;5;244mE/flutter (20575): #28     Element.rebuild[39;49m
[38;5;244mE/flutter (20575): #29     ComponentElement._firstBuild[39;49m
[38;5;244mE/flutter (20575): #30     StatefulElement._firstBuild[39;49m
[38;5;244mE/flutter (20575): #31     ComponentElement.mount[39;49m
[38;5;244mE/flutter (20575): #32     Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #33     Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #34     ComponentElement.performRebuild[39;49m
[38;5;244mE/flutter (20575): #35     Element.rebuild[39;49m
[38;5;244mE/flutter (20575): #36     ComponentElement._firstBuild[39;49m
[38;5;244mE/flutter (20575): #37     ComponentElement.mount[39;49m
[38;5;244mE/flutter (20575): #38     Element.inflateWidget[39;49m
[38;5;244mE/flutter (20575): #39     Element.updateChild[39;49m
[38;5;244mE/flutter (20575): #40     SliverMultiBoxAdaptorElement.updateChild[39;49m
[38;5;244mE/flutter (20575): #41     SliverMultiBoxAdaptorElement.createChild.<anonymous closure>[39;49m
[38;5;244mE/flutter (20575): #42     BuildOwner.buildScope[39;49m
[38;5;244mE/flutter (20575): #43     SliverMultiBoxAdaptorElement.createChild[39;49m
E/flutter (20575): #44     RenderSliverMultiBoxAdaptor._createOrObtainChild.<anony

2 个答案:

答案 0 :(得分:4)

[更新]插件的新版本修复了该错误。请使用0.13.4

audioplayers:0.13.4

好吧,我能够解决这个问题。这是0.13.3中引入的错误。因此,首先在pubspec.yaml文件中将您的依赖关系修正为0.13.2

audioplayers: 0.13.2

然后运行flutter clean,然后重新构建。它对我有用。

答案 1 :(得分:0)

只需重新启动应用程序