Skip to content

Instantly share code, notes, and snippets.

@kazuman519
Created May 19, 2016 07:50
Show Gist options
  • Select an option

  • Save kazuman519/f8914f0b63884993015474b3556de6c5 to your computer and use it in GitHub Desktop.

Select an option

Save kazuman519/f8914f0b63884993015474b3556de6c5 to your computer and use it in GitHub Desktop.
【Android】他アプリで音楽が再生されているか知りたい 自アプリからプレイヤーを操作したい ref: http://qiita.com/kazuman519/items/f470851b7fb7cb75794e
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.isMusicActive()) {
// 再生中!!
}
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
if (audioManager.isMusicActive) {
// 再生中!!
}
Intent intent = new Intent("com.android.music.musicservicecommand");
// play: 再生, pause: 停止, next: 次へ, preview: 前へ
intent.putExtra("command", "pause");
context.sendBroadcast(intent);
val intent = Intent("com.android.music.musicservicecommand")
// play: 再生, pause: 停止, next: 次へ, preview: 前へ
intent.putExtra("command", "pause")
context.sendBroadcast(intent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment