12

在我的 Android 应用程序中,我想在暂停后播放或恢复播放的音乐。我让我的应用程序通过发送广播暂停音乐,但我无法让它播放或恢复音乐。

这是暂停的代码:

Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
sendBroadcast(i);
4

2 回答 2

24

这是我在测试这些后发现的。

我已经尝试并验证了这些命令可以正常工作。

// pause
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
sendBroadcast(i);

// play
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "play");
sendBroadcast(i);

// next
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "next");
sendBroadcast(i);

// previous
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "previous");
sendBroadcast(i);

有关可用命令的更多信息:

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 CMDPLAY = "play";
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";

取自: https ://android.googlesource.com/platform/packages/apps/Music/+/master/src/com/android/music/MediaPlaybackService.java

于 2013-06-24T23:49:40.873 回答
1

尝试使用

Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "togglepause");
sendBroadcast(i);

更新

尝试以下操作:

Intent i = new Intent("com.android.music.musicservicecommand.togglepause");
i.putExtra("command", "togglepause");
sendBroadcast(i);
于 2013-02-16T12:41:05.670 回答