B4A Library esAudioMediaBrowser library

Hi,
Attached is a library for listing the audio content of the MediaStore and an example of it in use. This is built using the standard android mediaplayer and mediastore API 1.0 so should work on all versions of android, I have only tested it on Android 2.2.
To get a list of all audio on the device use
Code: Copy
myMap = mymedia.MediaAudioList()
this returns a 'Map' containing the following data for all of the audio media.
"Title"
"Album"
"Artist"
"ID"
"Data"
"DisplayName"
"Duration"
The format of the 'Map' is
Key = Titlen where n is an int from 0 to Map.length/7 (we divide by 7 because every media file returned has the above 7 fields in the map)
This format is repeated for all of fields. So to get the title of the 55th song in the MediaStore we use
Code: Copy
myMap.get("Title" & i)
where i = 54 (zero based).
To play a song use
Code: Copy
mymedia.MediaAudioPlay(Value)
where Value is the ID of the song as listed in the 'Map'
There is one event raised "Media_MediaCompleted" this is raised when the song has finished playing, the name is set in the initialization
Code: Copy
mymedia.Initialize("Media")
The other functions in the library are for controlling the media player;
Start,Stop,Pause,Play,Seek,Length & Position.
The simple example makes use of them all.

Update 1.1
Added the facility to sort the files.
Code: Copy
mymedia.MediaAudioList("title")
The fields that can be sorted on are;
Null
"Title"
"Album"
"Artist"
"_data"
"_display_name"
"Duration"
The values passed must be as displayed above although they are not case sensitive and only one field at a time.

For Info on sorting;
Additional parameters can be included with the column name see post #10 for more detail.
 

Attachments

Last edited:
Not every song will have all of the fields filled, it depends on how the song was uploaded to the device. Some of mine do not have artist or album but they should all have a title as a minimum.
 
Update 1.1 Sort on fields

See the first post for the update, added the facility to sort the request.
 
Hi that is easily fixed as the under lying java is making a database query all you have to do is include in your request,
Code: Copy
myMap = mymedia.MediaAudioList("title COLLATE NOCASE")
So any option you can normally put in a sqlite sort request can be added after your column name 'title' in this case, you do not need "ORDER BY" as this is assumed for this field. Have a look at Datatypes In SQLite Version 3 for the options. An additional option not mentioned is 'COLLATE UNICODE', which also sorts umlauts like "ä" correctly.
 
No it does not need this permission I had used an old template and did not remove it. It also does not need to be an activity object I also removed this but have not updated the library here as you will be posting the updated version.
 
so i can use you library to have access to mediastore and then i can use mediaplayer to play the files.. it's correct?
thanks!
 
if i list files with:
Code: Copy
Dim myMap As Map
myMap = mymedia.MediaAudioList("title")         
...
For i = 0 To (myMap.Size / 7) - 1               
   ListView1.AddTwoLines2(myMap.get("Title" & i) , myMap.get("Artist" & i), myMap.Get("ID" & i))
Next
....
Sub ListView1_ItemClick (Position As Int, Value As Object)
        
        FilePath= ????????

   MediaPlayer1.Load(FilePath, ChosenName)
   timer1.Initialize("timer1", 1000)
   MediaPlayer1.Play ' media is playing
        timer1.Enabled = True
.....
but how can I retrieve a file from the map and pass it to the media player?

i need of file PATH to load in mediaplayer... or?
thanks..
 
Last edited:
Back
Top