How can I import .mp3 files onto a list automatically?

Hello.

I´m building an app that you can add mp3 files onto a list to listen to them (basicly a music player app)
But the problem is that you gotta add the songs manually so it would be better that when opening the app for the first time, all of the mp3 files would import to the list by itself.
I want to do what @Anke did with the play from sdCards (https://drive.google.com/file/d/1gy_yDbk0yLgQBqbCeQViIPek90OFHFGX/view?usp=sharing)

If you know the path to the directory the mp3s are stored in, you could

and
loadMp3

and

loadMp3FolderToListPicker
to load the titles to a ListPicker.

This might not work when nb187 is released. The code loads the mp3s from my external sdCard.

This APK was built on the test server (targetSdk = 30).
Try it especially on Android 11 devices with a removable (micro) SD card.

Note:
This request is addressed to everyone who has an Android 11 device with an external (removable) SD card. Please test it and tell us if it works there too.
(It works (tested) on Android 11 devices without a removable SD card.)

Unfortunately, I have neither an Android 10 nor Android 11 test device with an external (removable) SD card.

Screenshots: → mp3 list with path → without path

It seems to work even on Android 11:

working on a Samsung A51 running Android 11

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like

Thanks, good to know that it also works on Android 11 devices from different manufacturers.

Btw, I don't think it's possible to do this with the (new) File component (test server).
I used your TaifunFile extension.

I did this method and it does read the files on the sd card automaticly but, when the app starts it returns this error:
The operation add items to list cannot accept the arguments: , [""], ["/storage/2295-1DEA/Music/Minecraft.mp3"]
These are my blocks:

And also, why is the replacement needed and the two empty text blocks?


I changed it to this and it does play the audio.
(I know that the path is needed but since the listPicker selection contains the path, I removed it.)

the error message happens in an add items to list block...
you do not show your relevant blocks...
it looks like your list is not a list...

Taifun

What do you mean by that?

I thought this were my relevant blocks since the error happens when screen initialize

the error message tells you, that it occurs while using an add items to list block

also this [""] from the error message looks like you are using an empty text block rather than a create empty list block for the list

Taifun

What is about the .AfterFileListAsync event / block?

I think the problem is the replacement block..

Ohhh, I forgot about that.. my bad

ok, so how did you initialize the global variable songList?
protip: my previous answer could help you to fix your bug...

Taifun

If the mp3 title has a space, replace the space with a control character. An mp3 like Swingin Safari.mp3 would not play with a space.

songListPicker

Two empty text Blocks...just me experimenting, they are not needed.

I did not want the ListPicker to display the path. Artistic license.

1 Like

Ohh ok.

Yeah, me too, I don´t want it to show the path. But how do I do that?

Yes it did work, I was adding an empty text block instead of a create empty list

Already provided the code. See when TaifunjFile1.AfterFileListAsync Event Handler.
Create global musicFiles and create global songList Lists. The add items to list Block creates a new List without the path and strips the path information. What you place in segment depends on your path (not mine). Set that list to the ListPicker.Elements and see what happens.

1 Like

Yeah, i just realized that it was a different path and that´s why it was showing the path

Did you try my test APK?

If so, does it work for you?