更新时间:2023-02-03 10:00:24
以下code将暂停一个默认的MediaPlayer通过发送一个广播:
The following code will pause a default MediaPlayer by sending a broadcast:
AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager.isMusicActive()) {
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "pause");
YourApplicationClass.this.sendBroadcast(i);
}