0
이제는 다른 음악 플레이어도 제어하고 있습니다. 시작한 후 기본 음악 플레이어가있는 경우 음악 플레이어로 재생을 시작한 다음 헤드셋에서 재생/일시 중지 단추를 누르면 기본 음악 플레이어가 제어됩니다. 내가 이런 heaset의 브로드 캐스트 리시버를 구현 한 ,헤드셋 버튼 컨트롤
switch (keyEvent.getKeyCode()) {
case KeyEvent.KEYCODE_HEADSETHOOK:
Log.d("TAG", "TAG: KEYCODE_HEADSETHOOK");
if (MusicService.isPlaying()) {
MusicService.player.pause();
} else {
MusicService.player.start();
}
new MusicService().showNotification();
break;
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Log.d("TAG", "TAG: KEYCODE_MEDIA_PLAY");
if (MusicService.isPlaying()) {
MusicService.player.pause();
} else {
MusicService.player.start();
}
new MusicService().showNotification();
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
break;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
Log.d("TAG", "TAG: KEYCODE_MEDIA_PAUSE");
break;
case KeyEvent.KEYCODE_MEDIA_STOP:
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
Log.d("TAG", "TAG: KEYCODE_MEDIA_NEXT");
if (MusicService.player.isPlaying()) {
MusicService.player.stop();
}
if (MusicService.songPosn < (MusicService.song.size() - 1)) {
MusicService.songPosn = MusicService.songPosn + 1;
if (SingleInstance.getInstance().getIndexCount()>= 1)
SingleInstance.getInstance().setIndexCount(SingleInstance.getInstance().getIndexCount()-1);
} else {
// play first song
MusicService.songPosn = 0;
}
new MusicService().playSong(true);
break;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
Log.d("TAG", "TAG: KEYCODE_MEDIA_PREVIOUS");
if (MusicService.player.isPlaying()) {
MusicService.player.stop();
}
if (MusicService.songPosn > 0) {
MusicService.songPosn = MusicService.songPosn - 1;
} else {
// play last song
MusicService.songPosn = MusicService.song.size() - 1;
}
new MusicService().playSong(true);
break;
}
답장을 보내 주셔서 감사합니다. 대답의 첫 부분이 나에게 유용했다. 하지만 헤드셋에서 재생/일시 중지 버튼을 누르면 내 음악 플레이어에 오디오 포커스를 얻고 싶습니다. – gagan08