Android pause or stop playback of other music players implement code _android

Source: Internet
Author: User

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);
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.