Android Question how can I play all music on SD card ?

khosrwb

Active Member
Licensed User
hello to all
I will find all music file in the SDcard and list them and play them
actually I want make a music player
my problem is : I can't play all music , actually I can play a one music
how can I play all music ?
 

Attachments

Last edited:

khosrwb

Active Member
Licensed User
You can only play a single file at a time. You can handle the Completed event to load the next file and play it.
yes it's true
I will play SD card music ((mp3))
Songs are played in sequence
how can I handle the Completed event to load the next file and play it ?
thanks you for your help
 
Last edited:

ac9ts

Active Member
Licensed User
You have a list of all your music, correct?

You can start and play a single song, correct?

I'm assuming you are using MediaPlayer, correct?

When you initialize the MediaPlayer, you gave it an event name, correct?

Once the currently playing song completes, a sub is called by the MediaPlayer. In this sub, you will start your next song.

For a simple example:

B4X:
Dim MP As MediaPlayer
MP.Initialize2("MP")      ' Very Important!! You HAVE to use initialize2 to handle the complete event!!
MP.Load("MP3", "Song1.mp3")
MP.Play
Once the song completes, it will call Sub MP_Complete (or whatever event name you give it with _Complete as the suffix). In this sub, you load and play the next song.

B4X:
Sub MP_Complete

MP.Load("MP3", "Song2.mp3")
MP.Play

End Sub
It's up to you on how you want to determine and keep track of which song will be played next. This post just has the basics of playing one song after the next. Good Luck!
 

khosrwb

Active Member
Licensed User
You have a list of all your music, correct?

You can start and play a single song, correct?

I'm assuming you are using MediaPlayer, correct?

When you initialize the MediaPlayer, you gave it an event name, correct?

Once the currently playing song completes, a sub is called by the MediaPlayer. In this sub, you will start your next song.

For a simple example:

B4X:
Dim MP As MediaPlayer
MP.Initialize2("MP")      ' Very Important!! You HAVE to use initialize2 to handle the complete event!!
MP.Load("MP3", "Song1.mp3")
MP.Play
Once the song completes, it will call Sub MP_Complete (or whatever event name you give it with _Complete as the suffix). In this sub, you load and play the next song.

B4X:
Sub MP_Complete

MP.Load("MP3", "Song2.mp3")
MP.Play

End Sub
It's up to you on how you want to determine and keep track of which song will be played next. This post just has the basics of playing one song after the next. Good Luck!

hi

Code:
Dim MP AsMediaPlayer
MP.Initialize2("MP")
MP.Play

I know that , I can play one music
but I don't make list of mp3 files and then play them
if possible please help me

thanks
 

Attachments

Last edited:

ac9ts

Active Member
Licensed User
Use the MediaBrowser library to list all the audio files on your device.

http://www.b4x.com/android/forum/threads/lib-mediabrowser.19121/

If this is for your own use and you will always know where the MP3 files are located, just read the directory and parse the file names.

B4X:
Sub MP_Complete

MP.Load("MP3", "Song2.mp3")  ' <-- Change THIS to play the next song on the list.
MP.Play

End Sub
 
Last edited:

JoanRPM

Active Member
Licensed User
Here you are a simple example.

You need to create a directory called "musica" in DirRootExternal, and put the file songs in it.
To play from the SD card you need to change the "DirRootExternal" to the sd directory. Search in the forum were is located (I think it's "/mnt/external_sd") but it depends on your device.

Good luck.
 

Attachments

khosrwb

Active Member
Licensed User
Here you are a simple example.

You need to create a directory called "musica" in DirRootExternal, and put the file songs in it.
To play from the SD card you need to change the "DirRootExternal" to the sd directory. Search in the forum were is located (I think it's "/mnt/external_sd") but it depends on your device.

Good luck.
thanks Joan
 
Top