2

In my application, I need to launch the Android Music Player. And, for now, it works perfectly :

Intent  intent = new Intent(android.content.Intent.ACTION_VIEW); 
File    file = new File(file_path);

intent.setDataAndType(Uri.fromFile(file), "audio/*");  
startActivity(Intent.createChooser(intent, "..."));

But the user can't use the "next" and "prev" buttons to switch music. That's why I try to launch multiple songs at once (a playlist). And I don't really know how to do this! Give an array to the intent ?

Community
  • 1
  • 1
Mathieu Mahé
  • 2,647
  • 3
  • 35
  • 50

2 Answers2

2

As far I know there is no way to launch multiple tracks. But you can implement your player, using the MediaPlayer class. Which also doesn't supports multiple tracks. So you also have to make a service, use OnCompletionListener to listen when tracks finish, to start the next track.

This thread will help: How do Android mediaplayers continuing playing songs when app is closed?

Also this one: Start default music player with music playing by default

Community
  • 1
  • 1
User
  • 31,811
  • 40
  • 131
  • 232
2

yes their is no direct way to get multiple songs using intent . but you can fetch selected songs. play one by one by your code.using media player. set songs in queue . For your purpose you had to make your own media player.

using this code for picking multiple songs sourcetopickmultiplesongs;

store the selected song array.

play one after other using this piece of code .

MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.raw.sound1);  
MediaPlayer mp2=MediaPlayer.create(getBaseContext(), R.raw.sound2);         

mp1.prepare();
mp2.prepare();   
mp1.start();
mp1.setNextMediaPlayer(mp2);

hope this helps .

ShujatAli
  • 1,376
  • 2
  • 14
  • 26