React-native-sound: isPlaying() always returns false on Android

Created on 20 Jun 2018  路  4Comments  路  Source: zmxv/react-native-sound

Environment:

"react-native": "0.55.4",
"react-native-sound": "^0.10.9",

Issue:
While audio is playing and I call sound.isPlaying() the result is always false. On iOS is working correctly. I want to be able to show either a play or pause button depending on the state.

Investigation:
I can see in sound.js there is an event listener which listens for an event named onPlayChange which changes the value of the field _playing.
https://github.com/zmxv/react-native-sound/blob/master/sound.js#L44

      this.onPlaySubscription = eventEmitter.addListener(
        'onPlayChange',
        (param) => {
          const { isPlaying, playerKey } = param;
          if (playerKey === this._key) {
            if (isPlaying) {
              this._playing = true;
            }
            else {
              this._playing = false;
            }
          }
        },
      );

When looking at the native iOS code I can see this event gets fired from a callback as expected
https://github.com/zmxv/react-native-sound/blob/master/RNSound/RNSound.m#L308

- (void)setOnPlay:(BOOL)isPlaying forPlayerKey:(nonnull NSNumber*)playerKey {
  [self sendEventWithName:@"onPlayChange" body:@{@"isPlaying": isPlaying ? @YES : @NO, @"playerKey": playerKey}];
}

This looks different to the Android implementation found here:
https://github.com/zmxv/react-native-sound/blob/master/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java#L43

  private void setOnPlay(boolean isPlaying, final Double playerKey) {
    final ReactContext reactContext = this.context;
    WritableMap params = Arguments.createMap();
    params.putBoolean("isPlaying", isPlaying);
    params.putDouble("playerKey", playerKey);
  }

I cannot see a native callback which tells the javascript code an audio file is now playing.

Is this also broken for others?
Thank you

Most helpful comment

+1
We hope to fix this problem as soon as possible. We really need you to solve it. Thank you

All 4 comments

any update with this?

Nope.. I have had to depend on my forked version with the fix as needed it for my app.

+1
We hope to fix this problem as soon as possible. We really need you to solve it. Thank you

I can verify that this works - My app wasn't receiving isPlaying() on android, and now it is after using metaware's fork :) metaware/react-native-sound

"react-native-sound": "git+https://[email protected]/metaware/react-native-sound.git",
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jacargentina picture jacargentina  路  4Comments

leenasn picture leenasn  路  5Comments

andrekovac picture andrekovac  路  5Comments

tanapats picture tanapats  路  3Comments

leannaweller picture leannaweller  路  5Comments