我试图播放一个声音,当一个按钮被点击,并决定使用“音频播放器”库为它。问题是,当我在井上运行我的应用程序时,我会发现一个奇怪的错误-
Error: NotSupportedError: Failed to load because no supported source was found.
at Object.createErrorWithStack (http://localhost:49201/dart_sdk.js:5076:12)
at Object._rethrow (http://localhost:49201/dart_sdk.js:40477:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:49201/dart_sdk.js:40473:13)
at Object._microtaskLoop (http://localhost:49201/dart_sdk.js:40330:13)
at _startMicrotaskLoop (http://localhost:49201/dart_sdk.js:40336:13)
at http://localhost:49201/dart_sdk.js:35811:9我真不知道为什么会这样。我将尝试在仿真器上测试这一点,看看它是如何进行的。但现在这是密码-
这是密码-
class _PopScreenState extends State<PopScreen> {
late String currentPath;
AudioCache player = new AudioCache(); //relevant
void initState() {
super.initState();
currentPath = normalPaths[widget.id];
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: animalColorThemes[widget.id],
title: Text(
animalData[widget.id][0],
),
centerTitle: true,
),
body: GestureDetector(
onTapDown: (e) {
player.play("assets/pop1.mp3"); //relevant
setState(() {
currentPath = activePaths[widget.id];
});
},
onTapUp: (e) {
setState(() {
currentPath = normalPaths[widget.id];
});
},
child: Stack(
children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(
currentPath,
),
),
),
),
],
),
));
}
}发布于 2022-02-06 05:14:54
首先,您必须检查您是pubspec.yaml文件,并在其上注册资产文件夹,如下所示:
flutter:
assets:
- assets/audio/小心这个文件中的空间。然后您也可以使用这个库:音频播放器
第二个问题是拼写文件名。
https://stackoverflow.com/questions/71004277
复制相似问题