Luan Nico
Luan Nico

Reputation: 5917

Play custom audio

I'm trying to play an mp3 I will bundle with my app. I added it in the assets, just like the images, added to the pubspec, but can't make it play.

I tried two libraries, rxlabz/audioplayer and evrone/flutter_audio (medrecorder_audio), to no avail.

The first I tryed configuring to isLocal: true, added every conceivable callback, but it just returned the error:

Attempt to call getDuration without a valid mediaplayer

Which I couldn't relate to flutter/dart but found is a common error on Android, related to not calling prepare method. I checked their code, though, and they seem to be calling. I thought it my be async, so I waited a while after creating the player to call start, no luck.

The latter just gives the error "startPlay: FAIL" when I start play.

It seems these libs are made to play an audio that's on the user's cellphone, but I'm not sure. I want to play my own custom mp3 that I will bundle as an asset. Would someone shed some light?

Upvotes: 0

Views: 834

Answers (1)

Luan Nico
Luan Nico

Reputation: 5917

Thanks to @aziza's link, and a lot of experimenting, I found the problem.

The file to be played need to me an MP3; WAV just won't work, and will give a very cryptic error.

This class shows in details how to do it.

Upvotes: 1

Related Questions