How do I apply for a standard audio player?
1 answer
The music player is not standard on Android and vendors may come with a different app than others (i.e. Sony is a good example). Controlling a media application can be doable, but the end effect depends on which application is actually installed (and used, since the user can have more than one). You can control some, but others can remain invulnerable to your attempts. You can try this code - will work for Google Music for example):
public static final String SERVICECMD = "com.android.music.musicservicecommand";
public static final String CMDNAME = "command";
public static final String CMDSTOP = "stop";
AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
if(mAudioManager.isMusicActive()) {
Intent i = new Intent(SERVICECMD);
i.putExtra(CMDNAME , CMDSTOP );
YourApplicationClass.this.sendBroadcast(i);
}
other 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";
Commands are taken from android / music / MediaPlaybackService.java
0
source to share