我正在使用媒體播放器播放實況流。我有它的工作。但是,當我撥打電話並結束通話時,音頻會自動停止並恢復。Android媒體播放器收到來電後不能恢復。
但是,當我收到來電時,音頻停止並且不再恢復。
我用下面的代碼來實現。 Handling Android application pause on incoming call and resume after call end。 但這不起作用。以下是我的代碼。我已將以下內容用作服務以及在使用媒體播放器的同一活動中。
private void callsettings() {
PhoneStateListener phoneStateListener = new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
// TODO Auto-generated method stub
super.onCallStateChanged(state, incomingNumber);
if (state == TelephonyManager.CALL_STATE_RINGING) {
mute();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
Unmute();
} else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
mute();
}
}
};
TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (mgr != null) {
mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
private void mute() {
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
//am.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
}
private void Unmute() {
am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//am.setStreamVolume(AudioManager.STREAM_MUSIC, 5, 0);
am.setStreamMute(AudioManager.STREAM_MUSIC, false);
}
請幫我這裏,idk這個問題的原因是什麼。預先感謝。
你必須存儲尋求視頻的時間,而活動遷出用戶屏幕和節省尋找時間將使用恢復視頻的最後狀態。 –
感謝您的快速評論輥。但我正在使用音頻直播,我認爲它很難獲取尋找時間。 –
你能分享代碼snipet嗎?我認爲這個狀態圖會幫助你:http://developer.android.com/reference/android/media/MediaPlayer.html –