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
B4X:
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
B4X:
myMap.get("Title" & i)
where i = 54 (zero based).
To play a song use
B4X:
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
B4X:
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.
B4X:
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

  • AudioBrowserExample1_1.zip
    70.9 KB · Views: 573
  • esAudioMediaBrowserLibrary1_1.zip
    5.9 KB · Views: 563
Last edited:

Informatix

Expert
Licensed User
Longtime User
if i list files with:
B4X:
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..

"Location"

You should look at the demo. The file path is displayed in the scrollview by this line (and two others for video and image):
lstAudio.AddItemNoChkbx(m.Get("ID" & i), m.Get("Title" & i), m.Get("Location" & i), Null)

There's also a function SplitLocation (remove the comment marks) to split the location returned in the map in filepath and filename.
 

stefanoa

Active Member
Licensed User
Longtime User
pnlsvtouc signature does not match expected signature

ok thanks!

Now, when i touch the screen, i have this error:

java.lan.Exception: Sub pnlsvtouc signature does not match expected signature. Continue?

then if i continue, crash.

i've tried also with your demo and same error!
:sign0085:
 

stefanoa

Active Member
Licensed User
Longtime User
you have informations about a "bar" creation to move position of playing file?

for ex:
B4X:
Sub barPosition_ValueChanged (Value As Int, UserChanged As Boolean)
   
   MB.MediaPosition  = Value / 100 * MB.MediaLength 

   timer1_Tick 'immediately update the progress label
End Sub

i have this error:

unexpected type
required: variable
found : value
mostCurrent._mb.MediaPosition() = (int)(_value/(double)100*mostCurrent._mb.MediaLength());

on field _mb.MediaLength
 

Stulish

Active Member
Licensed User
Longtime User
Is there a way to display the images saved in the file (if they are saved as part of the file), or do you have to get the image separately (say from the folder they are held in), i dont know much about how audio files save this information.

But i have the rest of the library working well, i had to make a subroutine up to display the time correctly when getting the 'Duration' from the myMap.Get("Duration" & i)

Thanks
 

Informatix

Expert
Licensed User
Longtime User
you have informations about a "bar" creation to move position of playing file?

for ex:
B4X:
Sub barPosition_ValueChanged (Value As Int, UserChanged As Boolean)
   
   MB.MediaPosition  = Value / 100 * MB.MediaLength 

   timer1_Tick 'immediately update the progress label
End Sub

i have this error:

unexpected type
required: variable
found : value
mostCurrent._mb.MediaPosition() = (int)(_value/(double)100*mostCurrent._mb.MediaLength());

on field _mb.MediaLength

MediaPosition is readonly. Use MediaSeek instead.
 

Informatix

Expert
Licensed User
Longtime User
Is there a way to display the images saved in the file (if they are saved as part of the file), or do you have to get the image separately (say from the folder they are held in), i dont know much about how audio files save this information.
Do you speak of cover images ?
They are either stored in files or stored in folders. You have to decode the file if it's stored inside.
 

ibra939

Active Member
Licensed User
Longtime User
Thanks so good

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
B4X:
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
B4X:
myMap.get("Title" & i)
where i = 54 (zero based).
To play a song use
B4X:
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
B4X:
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.
B4X:
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.
 

ibra939

Active Member
Licensed User
Longtime User
Thanks so good

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
B4X:
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
B4X:
myMap.get("Title" & i)
where i = 54 (zero based).
To play a song use
B4X:
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
B4X:
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.
B4X:
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.
 
Top