hyochan/react-native-audio-recorder-player

addPlayBackListener flood

sayem314 opened this issue · 2 comments

Version of react-native-audio-recorder-player

2.6.2

Platforms you faced the error (IOS or Android or both?)

Tested only on Android

Expected behavior

Should not flood and should only execute when playing

Actual behavior

The player event is fired too much in a row, it even also gets fired when the player is paused. The event should throttle and only fire when it's playing.

Steps to reproduce the behavior

  useEffect(() => {
    Player.addPlayBackListener((e: any) => {
      console.log(e);
    });

    return Player.removePlayBackListener;
  }, []);

Okay so setting Player.setSubscriptionDuration(1); does throttle subscription but there should be better defaults like 500ms or 1sec. However, it's still a valid issue since the subscription is fired even when in the player is in a pause state.

Closes in #286 with 3.0.0-beta.2 release!