How do I get a list of mp3 files and play them?

You must request and grant READ permission (READ_MEDIA_AUDIO on Android 13+ and READ_EXTERNAL_STORAGE on Android < 13), also in the Companion app.

Thank you. Will try.

To make it work for Companion you must only go to the app (Companion) settings and grant Music and Audio permission.

In the companion settings Music and Audio are granted. Still won't play. Will post blocks as soon as I've exhausted everything alse.

What's wrong now?

It should work, if there is any mp3 file. Post a screenshot from your test device of the folder /Download. TaifunFile version?

Android 14:

The files in the Download directory show in the Listpicker, so they are definately there. Comes up with an error 701 and then 703 after picking the sound.

Here

here

I don't know how to find the version of Taifun's ext.

Try to add file:// to get an absolute path while setting the source of the player
file:///storage/emulated/0/...
Btw. on my webpage App Inventor Extensions: File | Pura Vida Apps you could have found the jukebox example app which shows you what needs to be done

Taifun

Also use the Player component instead of Sound and ask for permission correctly

Taifun

@Taifun I tried to adapt your Jukebox example to my needs.
i.e Your example requests a list of mp3 files and m4u files, and then requests a random file be played. I understand most of the code. Anyway it didn't work.
I don't need any of that. All I need is to import a single mp3 and to be played before being saved in my app.
I can get the file to a listpicker, and picked. But I cannot get it to play. An error saying cannot load the file and another saying cannot play the file. These two are what I don't uderstand. Thanks for your help.

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


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

My blocks are in a right state at the mo. I gave up in dispair. I will post them shortly after I have tidied up.

I've tried everything, and I still don't know what I'm doing wrong.

There are several errors in your blocks

  1. you forgot the else part
If api version <= 33
Then ask for read external storage permission 
Else ask for read media audio permission
  1. get the file list after you got permission... currently you ask for permission and immediately try to get the list, this will not work
    I e. Moce that block into the button click event

  2. rename your variable newSound to listSounds

  3. learn to work with lists, there is no need to use those replace all text blocks

  1. if you only want to display the filename in the label, check again my jukebox example to find out how to do it

  2. the source property of the player expects the complete path to the sound file, see again the jukebox example

Taifun

Made the suggested changes to the blocks. When I try to pick a file it says Unable to load....

Should be "<"

Changed, thank you.

@Taifun
Must be nearly Xmas, 'cos I got it to work, sort of. I still have a few things to work out, but I should be good from here. Thank you both for your time and effort.
I'll be back.