本文介绍了停止音乐应用程序播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我搜索周围,但没有找到任何答案。我想我的应用程序,如果有音乐播放应用程序的音乐(如谷歌音乐),我的应用程序停止播放音乐。那可能吗?
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";命令从安卓/音乐/ MediaPlaybackService.java
更多推荐
停止音乐应用程序播放音乐
发布评论