Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Player issue while phone call is initiating and solution. #36

Open
nillbiplob opened this issue Nov 13, 2016 · 0 comments
Open

Player issue while phone call is initiating and solution. #36

nillbiplob opened this issue Nov 13, 2016 · 0 comments

Comments

@nillbiplob
Copy link

It was a major issue and I fixed as follows

File: PlaybackService.java

TelephonyManager telManager;
boolean wasPlayingBeforePhoneCall=false;

public class LocalBinder extends Binder {
    public PlaybackService getService() {
        return PlaybackService.this;
    }
}

@Override
public void onCreate() {
    super.onCreate();
    mPlayer = com.aapbd.mediaplayeraudio.player.Player.getInstance();
    mPlayer.registerCallback(this);

    telManager = (TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);
    if (telManager != null) {
        telManager.listen(phoneListener,
                PhoneStateListener.LISTEN_CALL_STATE);
    }
}


PhoneStateListener phoneListener = new PhoneStateListener() {
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
        if (state == TelephonyManager.CALL_STATE_RINGING) {
            if(mPlayer==null)
                return;
            wasPlayingBeforePhoneCall = isPlaying();
            pause();
        } else if (state == TelephonyManager.CALL_STATE_IDLE) {
            if(mPlayer==null)
                return;

            if (wasPlayingBeforePhoneCall) {
               play();
            }
        } else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
            // A call is dialing,
            // active or on hold
            if(mPlayer==null)
                return;
            wasPlayingBeforePhoneCall = isPlaying();
            pause();
        }
        super.onCallStateChanged(state, incomingNumber);
    }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant