本文介绍了控制Android的默认音乐播放器或任何其他音乐播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何控制Android的默认音乐播放器或任何其他球员?通过控制我的意思是暂停,播放,下一个等我一定要绑定的服务?我曾尝试使用了 IMediaPlaybackService
,但它不工作。当然是有出路的,因为我已经看到在Android Market控制音乐播放器应用程序。你知道吗?
解决方案
AudioManager mAudioManager =(AudioManager)getSystemService(Context.AUDIO_SERVICE);
如果(mAudioManager.isMusicActive()){
意图I =新的意图(SERVICECMD);
i.putExtra(CMDNAME,CMDSTOP);
YourApplicationClass.this.sendBroadcast(ⅰ);
}
您可以通过获得audiomanager然后发送命令给它。
这是命令。
公共静态最后弦乐CMDTOGGLEPAUSE =togglePause时;
公共静态最后弦乐CMDPAUSE =暂停;
公共静态最后弦乐CMD preVIOUS =previous;
公共静态最后弦乐CMDNEXT =下一步;
公共静态最后弦乐SERVICECMD =com.android.music.musicservicecommand;
公共静态最后弦乐CMDNAME =命令;
公共静态最后弦乐CMDSTOP =停止;
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.
these are the commands.
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";
这篇关于控制Android的默认音乐播放器或任何其他音乐播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!