Play multiple songs with Android intent

不羁的心 提交于 2019-12-11 01:49:08

问题


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 ?


回答1:


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




回答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 .



来源:https://stackoverflow.com/questions/13519519/play-multiple-songs-with-android-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!