I am developing an application where I need to start the default music app and play all the songs. I have tried a number of approaches, but nothing seems to work.
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(
"com.android.music.MediaPlaybackActivityStarter");
startActivity( LaunchIntent );
and
Intent intent = new Intent();
ComponentName comp = new ComponentName("com.android.music",
"com.android.music.MediaPlaybackActivity");
intent.setComponent(comp);
intent.setAction(Intent.ACTION_RUN);
startActivity(intent);
Just starts the music player
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "1");
startActivity(i);
Plays just the first song.
To simply launch the music player do:
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);
please note, that this works only in SDK API level 8 up
Use this for api below 15
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
inintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
and later use android.intent.category.APP_MUSIC
.
I think you should implement your playlist which you can pass your list to mediaplayer and set your next song in mediaplayer.onCompletion ().
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.d("ON COMPLETE", "true");
player.isCompleteTrack = true;
if (mPlaylist.isLastTrack()) {
Log.i(PLAYER_ENGINE_TAG, " end playlist");
stop();
} else {
Log.i(PLAYER_ENGINE_TAG, " next song");
next();
}
}
});
Next()
@Override
public void next() {
if (!mPlaylist.isEmpty()) {
mPlaylist.setSelectedMedia(mPlaylist.getSelectedMedia() + 1);
}
play();
}
Or you can try open m3u (playlist) file.
I recently also started getting this issue after some security updates.
To solve this you need to disable all notifications from the default music player.
Do this by going to Settings/Apps & Notifications/Apps/Music
Then make sure all notifications are set to off and also block the app from accessing your storage.