flutter - 颤振 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(() {});
});
}
}
解决方案
推荐阅读
- xaml - 在 Xamarin.Forms 上绑定网格列宽
- linux - 当我尝试使用 wget 在服务器上下载文件时出现凭据问题
- safari - AppleScript:查找和设置窗口
- json - gfortran 在 Visual Studio Code 中链接和编译子程序
- sql - 仅在值更改时更新值
- node.js - 我可以将默认脚本行添加到 package.json
- javascript - RXJS + Axios 错开网络请求
- mysql - 谁能解释一下黑客等级二叉树节点的解决方案?
- arrays - 按升序对数组进行排序 - React js
- python - 一个不清楚的 requirements.txt 错误,导致无法安装