2

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.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
sarveshs
  • 68
  • 1
  • 2
  • 9

4 Answers4

1

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

Rahul Patel
  • 3,823
  • 5
  • 30
  • 46
  • Your code is simple start music player. But as i understand the OP want start and **play**. I run your code on NexusS (4.1.2). It only display player not play songs. – Trung Nguyen Dec 13 '12 at 07:08
  • MediaStore.INTENT_ACTION_MUSIC_PLAYER) is depricated in API level 15 – Dharmendra Oct 16 '13 at 07:15
1

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.

Mehrdad
  • 708
  • 1
  • 17
  • 38
0

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.

Trung Nguyen
  • 7,442
  • 2
  • 45
  • 87
  • I want to play all the songs, not just 1 song. In other words, I want that the default music app open and start playing automatically(via code). – sarveshs Apr 26 '12 at 08:16
  • Call me a noob, but isn't your code playing the songs in the same application using android.media.MediaPlayer. I am trying to open the default music app in android. – sarveshs Apr 26 '12 at 11:02
  • I've already told you should create your own player because it's hard to intercept the default built-in player. I found 2 similar questions [link](http://stackoverflow.com/questions/2030487/play-playlist-with-mediaplayer) he indicated that he can pass 1 list of song as a URI to play like 1 single song. And another [link] (http://stackoverflow.com/questions/6788156/intent-to-open-android-playlist-activity) – Trung Nguyen Apr 27 '12 at 08:26
  • Thanks for your help Yul but the need of the application is such that I have to play and stop it in the default player only. – sarveshs May 03 '12 at 06:26
  • If you find a solution, please add it here. I have a similar issue with built-in player. :) – Trung Nguyen May 03 '12 at 08:11
  • @Yul, I know this is to late, but If you need the solution then check my answer. – Rahul Patel Dec 13 '12 at 06:35
0

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.

Armali
  • 18,255
  • 14
  • 57
  • 171
Kevin
  • 1
  • 1