首页 > 解决方案 > 颤振 youtube_player_flutter:^7.0.0+7 http 请求错误

问题描述

我正在使用它package来播放视频,但我得到了这个error

HTTP request failed, statusCode: 404, https://i3.ytimg.com/vi_webp/qs8vn5rzs-0/sddefault.webp

When the exception was thrown, this was the stack: 
#0      NetworkImage._loadAsync (package:flutter/src/painting/_network_image_io.dart:99:9)
<asynchronous suspension>
Image provider: NetworkImage("https://i3.ytimg.com/vi_webp/qs8vn5rzs-0/sddefault.webp", scale: 1.0)
Image key: NetworkImage("https://i3.ytimg.com/vi_webp/qs8vn5rzs-0/sddefault.webp", scale: 1.0)

这是我的代码

class YouTubePage extends StatefulWidget {
  @override
  _YouTubePageState createState() => _YouTubePageState();
}

class _YouTubePageState extends State<YouTubePage> {
  @override
  void initState() {
    super.initState();
    getFevSub();
  }

  String fevSub = "music";
  void getFevSub() async {
    await FirebaseFirestore.instance
        .collection('users')
        .doc(FirebaseAuth.instance.currentUser.uid)
        .get()
        .then((data) {
      fevSub = data.data()['favSub'];
    });
    videoList(fevSub);
  }

  @override
  Widget build(BuildContext context) {
    return Scrollbar(
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Row(
            children: <Widget>[
                  SizedBox(width: 30),
                ] +
                widgetList),
      ),
    );
  }

  static String key;
  List<Widget> widgetList = [];
  YoutubePlayerController _controller;

  String videoID;
  bool _isPlayerReady = false;

  void videoList(fevSub) async {
    key = " ";
    YoutubeAPI ytApi = new YoutubeAPI(key, type: "video", maxResults: 10);
    List<YT_API> ytResult = [];
    ytResult = await ytApi.search(fevSub);
    ytResult.forEach((video) {
      String url = video.url;
      videoID = YoutubePlayer.convertUrlToId(url);
      _controller = YoutubePlayerController(
        initialVideoId: videoID,
        flags: YoutubePlayerFlags(
          autoPlay: true,
        ),
      );
      try {
        widgetList.add(
          YoutubePlayer(
            width: MediaQuery.of(context).size.width * 0.8,
            actionsPadding: EdgeInsets.all(10),
            liveUIColor: nave,
            controller: _controller,
            // showVideoProgressIndicator: true,
            progressIndicatorColor: yellow,
            progressColors: ProgressBarColors(
              playedColor: yellow,
              handleColor: nave,
            ),
            onReady: () {
              _isPlayerReady = true;
            },
          ),
        );
      } catch (e) {
        print(e);
      }
      widgetList.add(SizedBox(width: 15));
      setState(() {});
    });
  }
}

标签: flutter

解决方案


推荐阅读