I'm trying to play a sound when a button is clicked, and decided to use the "audioplayers" library for it. The problem is that when I run my app on the well I get this weird error-
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
I dont't really know why this is happening. I'll try testing this on an emulator and see how it goes. But for now here's the code-
Here's the code-
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,
),
),
),
),
],
),
));
}
}
CodePudding user response:
first of all you have to check you're pubspec.yaml file and register assets folder on it like this:
flutter:
assets:
- assets/audio/
be careful about space in this file. then you can use this library too: audio player
the second cuase this error is spelling you file name.
