Android Music Player 응용 프로그램을 개발 중입니다. 전화가 왔을 때 일시 중지하고 싶을뿐 아니라 Telephony Manager를 사용하여 확인할 수도 있지만 Whatsapp 호출 및 기타 인터넷 전화는 만들어 볼까 그
수 이것은 내가에서 코드를 대처 피할 수 있습니다Whatsapp을 감지하고 ExoPlayer를 일시 중지합니다.
private void player_manager_on_call() {
// TODO Auto-generated method stub
// Manage player on Call
phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING)
// Incoming // call: // Pause // music
{
try {
boolean is_playing = mediaController.Check_IsPlaying();
if (is_playing) {
Log.d("xiomi", "CALL_STATE_RINGING");
// Get details of song from sp
position = PlayerConstants.SONG_NUMBER;
data = PlayerConstants.SONGS_LIST.get(position);
Play_link = data.getPath();
Artist = data.getArtist() + "-" + data.getAlbum();
albumArt = UtilFunctions.getAlbumart(
getApplicationContext(), data.getAlbumId());
Log.e("albumArt", "albumArt " + albumArt);
mediaController.doPauseResume();
showControls();
// start notification service again for play
startNotificationService(MainActivity.this,
data.getTitle(), Artist, albumArt,
is_playing, position);
}
} catch (Exception e) { // TODO Auto-generated catch block
e.printStackTrace();
}
} else if (state == TelephonyManager.CALL_STATE_IDLE) // Not in
// //call:
// //
// Play
// //
// music
try {
if (player != null) {
Log.d("xiomi", "CALL_STATE_RINGING");
// Get details of song from sp
position = PlayerConstants.SONG_NUMBER;
data = PlayerConstants.SONGS_LIST.get(position);
Play_link = data.getPath();
Artist = data.getArtist() + "-" + data.getAlbum();
albumArt = UtilFunctions.getAlbumart(
getApplicationContext(), data.getAlbumId());
Log.e("albumArt", "albumArt " + albumArt);
boolean is_playing = mediaController
.Check_IsPlaying();
mediaController.doPauseResume();
showControls();
// start notification service again for play
startNotificationService(MainActivity.this,
data.getTitle(), Artist, albumArt,
is_playing, position);
}
} catch (Exception e) { // TODO Auto-generated catch block
e.printStackTrace();
}
else if (state == TelephonyManager.CALL_STATE_OFFHOOK) // A //
// call
// is // dialing, // active // or // on // hold
{
try {
boolean is_playing = mediaController.Check_IsPlaying();
if (is_playing) {
Log.d("xiomi", "CALL_STATE_OFFHOOK");
// Get details of song from sp
position = PlayerConstants.SONG_NUMBER;
data = PlayerConstants.SONGS_LIST.get(position);
Play_link = data.getPath();
Artist = data.getArtist() + "-" + data.getAlbum();
albumArt = UtilFunctions.getAlbumart(
getApplicationContext(), data.getAlbumId());
Log.e("albumArt", "albumArt " + albumArt);
mediaController.doPauseResume();
showControls();
// start notification service again for play
startNotificationService(MainActivity.this,
data.getTitle(), Artist, albumArt,
is_playing, position);
}
} catch (Exception e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
super.onCallStateChanged(state, incomingNumber);
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
whatsapp 호출은 전역 CALL 상태로 캡처되지 않을 수도있는 앱의 내부 상태 일 수 있습니다. –
'onPause'는 활동이 포커스를 잃을 때마다 트리거되므로'onPause'에서 이것을 처리 할 수 있습니까? –
@sunilsunny'onPause' 메서드는 처리 할 수 없습니다. 전화의 홈 버튼을 클릭하면이 메서드도 호출됩니다. 내 플레이어도 배경 플레이어 여야합니다. –