'How to play local audio using just_audio?

I have list of file path like this one: content://media/external/audio/media/2732 I want to play the audio using the given file path. How can I add that path as a media item?

MediaItem(
    id: "content://media/external/audio/media/2732",
    title: "Test Song",
)

Above code doesn't work.

Finally I found the solution. I used this package: URI to File.

Implementation

Uri uri = Uri.parse("content://media/external/audio/media/2732");
File file = await toFile(uri);
MediaItem(
    id: file.path,
    title: "Test Song",
)


Solution 1:[1]

Finally I found the solution. I used this package: URI to File.

Implementation

Uri uri = Uri.parse("content://media/external/audio/media/2732");
File file = await toFile(uri);
MediaItem(
    id: file.path,
    title: "Test Song",
)

Solution 2:[2]

you should try to add asset:/// in the start of your string.

example :

before : Uri.parse("content://media/external/audio/media/2732");

after : Uri.parse("asset:///content://media/external/audio/media/2732");

You can read that if you want : https://github.com/ryanheise/just_audio/blob/master/just_audio/example/lib/example_playlist.dart

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yubaraj Shrestha
Solution 2 Kerby Elpenord