I have started a development of a music player. I made some additional kotlin logic to retrieve all audio files meta data on device from the Android as a list of meta data. I'm trying to understand how a native path should look like for just_audio to understand. My current implementation uses a deprecated key - MediaStore.Audio.Media.DATA for contentResolver which returns a path like this /storage/emulated/0/Download/scifri20181123-episode.mp3. Can this path be used by the plugin or I need to find another way to retrieve the path in different format? The same question is valid for the album art.
Asked
Active
Viewed 1,073 times
1 Answers
5
Yes, if it's a valid file path, then just_audio will be able to open it. You could pass this into setFilePath
:
var filePath = '/storage/emulated/....../foo.mp3';
await player.setFilePath(filePath);
This is a convenience method for:
setAudioSource(AudioSource.uri(Uri.file(filePath)));
where Uri.file(filePath)
will create a Uri
instance containing something like file:///storage/emulated/....
. under the hood.
Note that if your app tries to access any file outside of its own app data/cache directories, it also requires permission to do so, and there are other Flutter packages available to help you with this.
Note also that there is also an existing flutter package using the content resolver API called flutter_audio_query, so if it contains what you need, you might not need to write your own Kotlin code.

Ryan Heise
- 2,273
- 5
- 14
-
When using `setAudioSource(AudioSource.uri(Uri.file(filePath)))`, can the file path point to assets directly in the flutter directory without extra permissions? I am trying to load local files into a playlist and getting a no such file error – gpickart Feb 17 '21 at 06:29
-
1There is another method called `setAsset(assetPath)` which is a convenience method for `setAudioSource(AudioSource.uri(Uri.parse('asset:///$assetPath'))`. This accesses the asset directly from the app's AssetBundle and does not require any special permissions. – Ryan Heise Feb 17 '21 at 13:02
-
I didn't know about that flutter package, I did everything my self :), I can compare what that plugin si doing – ZlatiP Feb 18 '21 at 17:57