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