停止音乐应用程序播放音乐

编程入门 行业动态 更新时间:2024-10-28 20:30:32
本文介绍了停止音乐应用程序播放音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

更多推荐

停止音乐应用程序播放音乐

本文发布于:2023-07-11 09:38:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:音乐   应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!