如何从我的代码播放或继续播放其他音乐播放器的音乐 [英] How to play or resume music of another music player from my code

查看:101
本文介绍了如何从我的代码播放或继续播放其他音乐播放器的音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,我想在暂停后播放或恢复播放的音乐.我将我的应用程序转到暂停音乐通过发送广播,但是我无法播放或继续播放音乐.

In my Android app I want to play or resume the played music after I pause it. I got my app to pause the music by sending a broadcast, but I can't get it to play or resume the music.

这是要暂停的代码:

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

推荐答案

在测试这些后,我发现了这些.

Here is what I have discovered after testing these.

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

I have tried and verified these commands to work just fine.

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

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

Some more info about available commands:

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

这篇关于如何从我的代码播放或继续播放其他音乐播放器的音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆