繁体   English   中英

如何从我的代码播放或恢复其他音乐播放器的音乐

[英]How to play or resume music of another music player from my code

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

这是暂停的代码:

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";

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

尝试使用

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM