Commit 1bf432ee authored by Sébastien Toque's avatar Sébastien Toque
Browse files

fix callback leak + pause playback for both incoming and outgoing calls

parent ad9a9cbf
......@@ -23,27 +23,21 @@ package org.videolan.vlc;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
public class PhoneStateReceiver extends BroadcastReceiver {
private PhoneStateListener mListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
LibVLC libVLC = LibVLC.getExistingInstance();
if (libVLC != null && libVLC.isPlaying())
libVLC.pause();
}
}
};
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager tm = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING) ||
state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
LibVLC libVLC = LibVLC.getExistingInstance();
if (libVLC != null && libVLC.isPlaying())
libVLC.pause();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment