使用 youtube_player_flutter 时无限加载

问题描述 投票:0回答:2

我正在使用 youtube_player_flutter 并按照自述文件中的说明正确实现了所有内容。

但我仍然面临一个问题,每当我打开我想要打开 YouTube 播放器的页面时,它都会不断加载并且从不加载视频。

我到处搜索这个问题但没有得到任何解决方案。其中一个解决方案是在

AndroidManifest.xml
中包含互联网许可:

<uses-permission android:name="android.permission.INTERNET"/>

我这样做了,没有任何改变。我还将软件包降级到 v6.1.1,有人在 github issues 中要求我这样做,但这也没有任何作用。

如何解决这个问题?

flutter dart github-issues
2个回答
7
投票

我正在回答我自己的问题,因为当我搜索这个问题时,我没有找到任何可以解决这个问题的东西。

所以,我尝试了

define the controller in initState()
并且成功了,现在是
working in v7.0.0+7
。这是我的代码:

class AboutTopic extends StatefulWidget {
  final String videoLink;

  AboutTopic({this.videoLink});

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

class _AboutTopicState extends State<AboutTopic> {
  YoutubePlayerController _controller;

  @override
  void initState() {
     _controller = YoutubePlayerController(
      initialVideoId:
          YoutubePlayer.convertUrlToId(widget.videoLink),
      flags: YoutubePlayerFlags(
          mute: false,
          autoPlay: true,
          disableDragSeek: true,
          loop: false,
          enableCaption: false),
    );

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
       appBar: AppBar(
        title: Text('About'),
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            Navigator.of(context).pop();
          },
        )
      ),

      body: YoutubePlayer(
        controller: _controller,
        showVideoProgressIndicator: true,
        bottomActions: <Widget>[
          const SizedBox(width: 14.0),
          CurrentPosition(),
          const SizedBox(width: 8.0),
          ProgressBar(isExpanded: true),
          RemainingDuration(),
        ],
        aspectRatio: 4 / 3,
        progressIndicatorColor: Colors.white,
        onReady: () {
          print('Player is ready.');
        },
      ),
    );
  }
}

0
投票

我也遇到这个问题了!我不会离开@littleironical,LMFAO。

视频加载无限,但是错误只出现在产品中,没有出现在模拟器中。我尝试过的:

1 - 在 AndroidManifest.xml 中包含互联网权限。

2 - 将控制器置于 initState 中。

3 - 增加包版本。

上面的尝试都没有任何效果,所以我决定将包降级到版本 8.0.0 并且它运行得很好。

© www.soinside.com 2019 - 2024. All rights reserved.