Play mp3 in google Play Music

2019-08-26 07:03发布

How can I play a mp3 song using Google Play Music.

I am trying to play, pause, next etc in Google Play Music.

I have set the music player as default.

I am able to broadcast the Next and previous by using the below commands.

    public static final String CMD_NAME = "CMD_NAME";
    public static final String CMD_PAUSE = "CMD_PAUSE";

    public static final String CMDTOGGLEPAUSE = "togglepause";
    public static final String CMDPAUSE = "pause";
    public static final String CMDPLAY = "play";
    public static final String CMDPREVIOUS = "previous";
    public static final String CMDNEXT = "next";
    public static final String SERVICECMD = "com.android.music.musicservicecommand";


AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

        if(mAudioManager.isMusicActive()) {
            Intent i = new Intent(SERVICECMD);
            i.putExtra(CMDNAME , CMDNEXT);
            this.sendBroadcast(i);
        }

How can I broadcast for play a song for a particular mp3 file (input as mp3 file name) .

1条回答
该账号已被封号
2楼-- · 2019-08-26 07:46

Haven't tested this but I believe you can create a Uri from the file that you want to play and send a share intent with this Uri...

After that a system dialog will ask the user what app they want to use to receive that intent. If configured correctly the music player should be able to handle the intent and play the song.

If the user selects to always use this app for this intent then the next times the dialog wont show and the player will handle the intent automatically.

Hope this helps

查看更多
登录 后发表回答