audio_waveforms icon indicating copy to clipboard operation
audio_waveforms copied to clipboard

fix bug: android call preparePlayer 2nd never callback

Open leconio opened this issue 2 years ago • 3 comments

  Future<void> preparePlayer(String path, [double? volume]) async {
    path = Uri.parse(path).path;

    await _readAudioFile(path);
    if ((_playerState == PlayerState.readingComplete &&
        _audioFilePath != null)) {
      final isPrepared = await AudioWaveformsInterface.instance
          .preparePlayer(path, _playerKey.toString(), volume);  <<<<<<<< block here
      if (isPrepared) {
        _maxDuration = await getDuration();
        setPlayerState(PlayerState.initialized);
      }
      notifyListeners();
    } else {
      throw "Can not prepare player without reading audio file";
    }
  }

leconio avatar Sep 12 '22 03:09 leconio

@leconio Can you please share the issue you were having? And you can use the same player for another audio you need to just call stop before calling preparePlayer for another audio

ujas-m-simformsolutions avatar Sep 12 '22 05:09 ujas-m-simformsolutions

Thanks, I run the example, I found the WaveBubble not update after recode a voice, It's a blank Bubble. The isRecoding state not update. The reason is preparePlayer not callback. Then I found the android api preparePlayer just only call once time because of a flag isPlayerPrepared. And the ios api is work very well.

leconio avatar Sep 14 '22 04:09 leconio

@leconio isPlayerPrepared's default value is already false and for updating UI based on the PlayerState I would recommend using the onPlayerStateChanged stream instead of using a listener or just playerState.

ujas-m-simformsolutions avatar Sep 22 '22 11:09 ujas-m-simformsolutions

closing this PR due to inactivity.

ujas-m-simformsolutions avatar Jan 05 '23 12:01 ujas-m-simformsolutions