Launching the default music player

Raz picture Raz · Feb 9, 2013 · Viewed 10k times · Source

I'm trying to launch the music player so it will launch and immediately start playing the first song. im using an Intent but it just doesn't work...it says "no activity found to handle intent".

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
       //"songsList" is an array with paths of all the songs in the sdcard
    Uri uri = Uri.parse(songsList.get(0));
    String type = "audio/mp3";
    intent.setDataAndType(uri, type);
    startActivity(intent);

Answer

Ahmad picture Ahmad · Feb 9, 2013

Why not use android.intent.action.MUSIC_PLAYER?

Intent intent = new Intent("android.intent.action.MUSIC_PLAYER");
startActivity(intent);

Note that this is deprecated from API 15, FROM API upwards you can use android.intent.category.APP_MUSIC.