在我的Android应用程序中,我想暂停后播放或恢复播放的音乐。我把我的应用程序带到pause the music by sending a broadcast,但我无法播放或恢复音乐。
这是暂停的代码:
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
sendBroadcast(i);
这是我在测试后发现的。
我已经尝试并验证了这些命令以便正常工作。
// 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";
尝试使用
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);