Search code examples
androidandroid-intentaudio-playerandroid-music-player

Play multiple songs with Android intent


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 ?


Solution

  • 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