I'm pretty new to Flutter and wanna try pogram an app just for fun and personal use. So I wanna play a MP3 and on my research I found the audioplayers package. All tutorials I could found was from really old versions and I could'nt figure out how to play a simple Audiofile from the phone. I startet with a FilePicker and select a file. Next step was to create an AudioPlayer and play the file, but whatever I've tried it won't work.
final AudioPlayer player = AudioPlayer();
File? selectedFile;
...
Future<File?> selectFile() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.audio,
allowedExtensions: ['mp3', 'wav'], // Erlaubte Audio-Dateiformate
);
if (result != null) {
setState(() {
selectedFile = File(result.files.single.path!);
});
return selectedFile;
}
}
void playSelectedFile() async {
if (selectedFile != null) {
int result = await player.play(DeviceFileSource(selectedFile!));
}
}
So thats the code. The main problem is that I don't really understand the audioplayers package and the audioPlayer.play(...) function, especially what format the data in the brackets needs and the different types. audioplayers on git: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md
Maybe someone can help :3
I've tried many variations to play a little Sound or MP3, but nothing was working. The main problem is to understand the package.