0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Luan Nico
  • 5,376
  • 2
  • 30
  • 60
  • have you checked this ?https://stackoverflow.com/questions/46486475/how-to-play-local-mp3-file-with-audioplayer-plugin-in-flutter/46498239#46498239 – Shady Aziza Oct 12 '17 at 04:34
  • @aziza that seems to be the perfect solution, but gives the same kind of error on mediplayer prepare. Do I have to enable some sort of permission to use audio? I tried playing a System Sound and it worked – Luan Nico Oct 13 '17 at 12:55
  • @aziza I made it! Finally! The problem was, my file was a wav, it needed to be mp3. Thanks so much! – Luan Nico Oct 22 '17 at 00:33
  • glad you have found your way to it, please consider answering your question. – Shady Aziza Oct 22 '17 at 07:04

1 Answers1

1

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.

Luan Nico
  • 5,376
  • 2
  • 30
  • 60