The code is as follows:
Copy Code code as follows:
public static final String playstate_changed = "com.android.music.playstatechanged";
public static final String meta_changed = "com.android.music.metachanged";
public static final String queue_changed = "com.android.music.queuechanged";
public static final String playback_complete = "Com.android.music.playbackcomplete";
public static final String async_open_complete = "Com.android.music.asyncopencomplete";
public static final String servicecmd = "Com.android.music.musicservicecommand";
public static final String CMDNAME = "command";
public static final String cmdtogglepause = "Togglepause";
public static final String cmdstop = "Stop";
public static final String cmdpause = "Pause";
public static final String cmdprevious = "previous";
public static final String cmdnext = "Next";
Private Broadcastreceiver Mintentreceiver = new Broadcastreceiver () {
@Override
public void OnReceive (context context, Intent Intent) {
String action = Intent.getaction ();
String cmd = Intent.getstringextra ("command");
if (cmdnext.equals (cmd) | | Next_action.equals (ACTION)) {
Next (true);
else if (cmdprevious.equals (cmd) | | Previous_action.equals (ACTION)) {
Prev ();
else if (cmdtogglepause.equals (cmd) | | Togglepause_action.equals (ACTION)) {
if (isplaying ()) {
Pause ();
} else {
Play ();
}
else if (cmdpause.equals (cmd) | | Pause_action.equals (ACTION)) {
Pause ();
else if (cmdstop.equals (cmd)) {
Pause ();
Seek (0);
else if (MediaAppWidgetProvider.CMDAPPWIDGETUPDATE.equals (cmd)) {
Someone asked us to refresh a set of specific widgets, probably
Because they were just added.
int[] Appwidgetids = Intent.getintarrayextra (appwidgetmanager.extra_appwidget_ids);
Mappwidgetprovider.performupdate (Mediaplaybackservice.this, appwidgetids);
}
}
};
Analysis can be concluded that there are two ways to suspend music, one is to send CMD directly, the other is to send action.
Pause the music playback code as follows:
Copy Code code as follows:
private void Pausemusic () {
Intent freshintent = new Intent ();
Freshintent.setaction ("Com.android.music.musicservicecommand.pause");
Freshintent.putextra ("command", "pause");
Sendbroadcast (freshintent);
}