停止音乐应用程序播放音乐 [英] Stop the music app to play music

查看:170
本文介绍了停止音乐应用程序播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索周围,但没有找到任何答案。我想我的应用程序,如果有音乐播放应用程序的音乐(如谷歌音乐),我的应用程序停止播放音乐。那可能吗?

I've searched around but haven't found any answers. I want my app, if there is music app playing music (e.g Google Music), stop the playing music from my app. Is that possible?

在此先感谢!

推荐答案

这取决于所使用的音频播放器。你可能能够控制一些,但其他可保持免疫。借助内置的一个,你可以试试这个code

It depends on audio player being used. You may be able to control some, but other may remain immune. With built-in one, you can try this code

public static final String SERVICECMD = "com.android.music.musicservicecommand";
public static final String CMDNAME = "command";
public static final String CMDSTOP = "stop";

AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

if(mAudioManager.isMusicActive()) {
    Intent i = new Intent(SERVICECMD);
    i.putExtra(CMDNAME , CMDSTOP );
    YourApplicationClass.this.sendBroadcast(i);
}

其他命令

public static final String CMDTOGGLEPAUSE = "togglepause";
public static final String CMDPAUSE = "pause";
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";

命令从<一所href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android-apps/1.5_r4/com/android/music/MediaPlaybackService.java\"相对=nofollow>安卓/音乐/ MediaPlaybackService.java

这篇关于停止音乐应用程序播放音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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