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
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
where i = 54 (zero based).
To play a song use
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
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.
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.
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
B4X:
myMap = mymedia.MediaAudioList()
"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
B4X:
myMap.get("Title" & i)
To play a song use
B4X:
mymedia.MediaAudioPlay(Value)
There is one event raised "Media_MediaCompleted" this is raised when the song has finished playing, the name is set in the initialization
B4X:
mymedia.Initialize("Media")
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.
B4X:
mymedia.MediaAudioList("title")
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: