Control the default music player of android or any other music player

后端 未结 7 1084
抹茶落季
抹茶落季 2020-11-28 06:05

How to control the default music player of android or any other player? By controlling i mean pause, play, next etc. Do i have to bind the service? I have tried to use the <

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 07:00

    AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    
    if(mAudioManager.isMusicActive()) {
        Intent i = new Intent(SERVICECMD);
        i.putExtra(CMDNAME , CMDSTOP );
        YourApplicationClass.this.sendBroadcast(i);
    }
    

    you can by getting the audiomanager then sending commands to it.

    these are the commands.

     public static final String CMDTOGGLEPAUSE = "togglepause";
     public static final String CMDPAUSE = "pause";
     public static final String CMDPREVIOUS = "previous";
     public static final String CMDNEXT = "next";
     public static final String SERVICECMD = "com.android.music.musicservicecommand";
     public static final String CMDNAME = "command";
     public static final String CMDSTOP = "stop";
    

提交回复
热议问题