-1

I am developing a flutter app. I want to let the user select some sounds. When selected, I want the app to play its mp3 file in the assets folder. I tried with AudioPlayer plugin but I haven't achieved to play local files... I have been searching for awhile and I haven't found any good answer to my questions, furthermore, the posts were created 2 or 1 year ago, so maybe we need an updated answer.

I have found this post: How to play local mp3 file with audioplayer plugin in Flutter but my project doesn't find this package import 'package:path_provider/path_provider.dart'; [THIS PART IS SOLVED]

And when flutter will have a built-in audio manager? Are they/you working on it? Thanks in advance!

EDIT: Also, I would like to play different mp3 at the same time, with different volume. Is it possible?

Raul Mabe
  • 453
  • 5
  • 15

1 Answers1

0

That import directive you see tells Dart that a particular source file uses classes from a different source file. The package: prefix tells Dart that the imported file is part of an external dependency. So you need to tell your project that you have a dependency. This is done in the pubspec.yaml file.

Dart's pub dependency manager takes care of finding the right version of the dependency for you, and downloading it. Add the path_provider package to your pubspec.yaml file. Each package's installing tab shows how to do this.

You can find a whole library of useful flutter (and Dart) packages here.

path_provider is a special type of package called a plugin which contains some Dart code together with iOS and Android specific code. This is necessary because playing audio or creating local files is platform specific.

Richard Heap
  • 48,344
  • 9
  • 130
  • 112
  • Thank you! Very useful info, I needed it! But still I have problems making it work the way I would like, I edited my post explaining my problem! – Raul Mabe May 04 '18 at 12:07
  • You would probably need to write your own plugin, but you could base anything you write on the existing AudioPlayer plugin. One of the benefits of Dart/Flutter is that it is open source. – Richard Heap May 04 '18 at 13:29
  • Yea, I have been lucky this time and I've found this [fork of audioPlayer](https://github.com/luanpotter/audioplayer) with my special needs, thank you! – Raul Mabe May 04 '18 at 19:07