ZlatiP
ZlatiP

Reputation: 205

Native file path

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.

Upvotes: 2

Views: 1388

Answers (1)

Ryan Heise
Ryan Heise

Reputation: 2786

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.

Upvotes: 5

Related Questions