I’m having a problem in flutter on vs code
I imported the audioplayers
here’s my pubspec.yaml
here’s my homepage where I call the audio players
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.brown,
title: Text('anghami'),
),
body: Container(
color: Colors.brown[200],
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Card(
child: ListTile(
title: Text(
"benab",
style: TextStyle(color: Colors.red),
),
//tileColor: Colors.red,
leading: Icon(Icons.music_note),
iconColor: Colors.red,
onTap: () async {
final player = AudioPlayer();
await player
.setSource(AssetSource('assets/music/music1.mp3'));
},
),
),
],
),
),
),
);
}
}
whenever i try to play the music from the phone I get this error
P.S: the vs code has no problem in loading images or using other type of assets .
i’ve tried using Audiocache it doesn’t work especially they deleted it in the last version ^1.1.1 ,
[enter image description here][https://i.stack.imgur.com/u9kKR.png]
4
Answers
Hello guys the solutions here are useful , so the main problem that I had was in the path so after correction it loaded the asset in a normal way, but instead of just loading the asset you want it to play obviously and that's guaranteed by using :
It seems you trying to load an asset in
/assets/assets/music/
folder.My guess is that you want to load an asset in
/assets/music/
folder and it’s a simple mistake.To fix that:
Firstly, create a
assets
directory on the root of your project , then createmusic
folder.Try to play with
Just remove assets from your audio source like this: