控制安卓或任何其他音乐播放器的默认音乐播放器 [英] Control the default music player of android or any other music player

查看:58
本文介绍了控制安卓或任何其他音乐播放器的默认音乐播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何控制安卓或任何其他播放器的默认音乐播放器?通过控制,我的意思是暂停、播放、下一步等.我必须绑定服务吗?我曾尝试使用 IMediaPlaybackService 但它不起作用.肯定有出路,因为我在 android 市场上看到了控制音乐播放器的应用程序.有什么想法吗?

How to control the default music player of android or any other player? By controlling i mean pause, play, next etc. Do i have to bind the service? I have tried to use the IMediaPlaybackService but it is not working. There is certainly a way out as i have seen apps in the android market which controls the music player. Any idea?

推荐答案

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

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

您可以通过获取音频管理器然后向其发送命令.

you can by getting the audiomanager then sending commands to it.

这些是命令.

 public static final String CMDTOGGLEPAUSE = "togglepause";
 public static final String CMDPAUSE = "pause";
 public static final String CMDPREVIOUS = "previous";
 public static final String CMDNEXT = "next";
 public static final String SERVICECMD = "com.android.music.musicservicecommand";
 public static final String CMDNAME = "command";
 public static final String CMDSTOP = "stop";

这篇关于控制安卓或任何其他音乐播放器的默认音乐播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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