React-native-track-player: Android - Phone Call Doesn't Fire Events

Created on 5 Nov 2018  路  8Comments  路  Source: react-native-kit/react-native-track-player

If there's an incoming phone call and/or I answer a phone call, no events seem to be fired by the library to get it to pause (or resume when phone call is finished).

Bug

Most helpful comment

@shuvo0074 Here's a pseudo code:

if(event === 'remote-duck') {
    if(data.paused) {
        TrackPlayer.pause();
        wasPlaying = true;
    } else if(data.ducking) {
        TrackPlayer.setVolume(0.5);
    } else {
        if(wasPlaying) {
            TrackPlayer.play();
            wasPlaying = false;
        }
        TrackPlayer.setVolume(1);
    }
}
  • When the event is triggered with paused set to true, you should pause your app.
  • When the event is triggered with ducking set to true, you should either lower the volume or pause the app. If it's a music app, you probably want to lower the volume, but if it's a podcast app, you probably want to pause it for a moment.
  • When the event is triggered and none of them are set to true, you should resume the track and set the volume back to its original value.

Note that the event will never be triggered with both paused and ducking set to true. It's either one of them or none.

All 8 comments

Please, try 311a907e5b511cdb7855491706dfa81ca3517276.
In the previous Android version, it used to call remote-pause on phone calls. Now, it should be calling remote-duck with additional properties:

  • paused: Whether you should be pausing or resuming the music
  • ducking: Whether you should lower or restore the volume (for instance, a notification sound should make your app duck for a second)

Seems to work perfectly -- I see the event firing, and I don't seem to need to do anything else from my side -- the app pauses and resumes nicely.

how do i implement remote-duck : paused ? @Guichaguri @jasongrishkoff

@shuvo0074 Here's a pseudo code:

if(event === 'remote-duck') {
    if(data.paused) {
        TrackPlayer.pause();
        wasPlaying = true;
    } else if(data.ducking) {
        TrackPlayer.setVolume(0.5);
    } else {
        if(wasPlaying) {
            TrackPlayer.play();
            wasPlaying = false;
        }
        TrackPlayer.setVolume(1);
    }
}
  • When the event is triggered with paused set to true, you should pause your app.
  • When the event is triggered with ducking set to true, you should either lower the volume or pause the app. If it's a music app, you probably want to lower the volume, but if it's a podcast app, you probably want to pause it for a moment.
  • When the event is triggered and none of them are set to true, you should resume the track and set the volume back to its original value.

Note that the event will never be triggered with both paused and ducking set to true. It's either one of them or none.

When getting a call/playing a music on an App/Youtube, it fires event remote-duck for pausing. But on call end/music stop, its doesn't fire remote-duck again for resuming it back.

Works perfectly for ducking(on/off) for lowering down the volume on notification/message.

@Jayiitb does it happen in 80b97301bf340fa29ab9d971b9781c81d578e243?

@Guichaguri Thanks a lot! It works perfectly for calls. 馃憤

But for the apps like Youtube, Play Music etc. it doesn't resume.

@Jayiitb they are also audio apps that hold the audio focus as long as they can, so it overrides ours, which is the expected behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sathyanarayan09 picture Sathyanarayan09  路  3Comments

fabiocosta88 picture fabiocosta88  路  3Comments

mckmarc picture mckmarc  路  4Comments

b3rkaydem1r picture b3rkaydem1r  路  3Comments

sagargheewala picture sagargheewala  路  3Comments