init method

void init()

==== Init data and the listener ====

Implementation

void init() {
  TencentCloudChat.instance.chatSDKInstance.messageSDK.init(
    onRecvMessageReadReceipts: onReceiveMessageReadReceipts,
    onRecvNewMessage: onReceiveNewMessage,
    onMessageDownloadProgressCallback: TencentCloudChatDownloadUtils.handleDownloadProgressEvent,
    onSendMessageProgress: onSendMessageProgressFromSDK,
    onRecvMessageModified: onReceiveMessageModified,
    onRecvC2CReadReceipt: onReceiveC2CMessageReadReceipts,
    onRecvMessageRevoked: onReceiveMessageRecalled,
    onRecvMessageRevokedWithInfo: onRecvMessageRevokedWithInfo,
  );
  player = AudioPlayer();
  player!.setVolume(1);
  player!.onPlayerStateChanged.listen(
    (PlayerState state) {
      console(logs: "onPlayerStateChanged ${state.name}, messageID: ${_audioPlayInfo?.msgID}");
      if (state == PlayerState.playing) {
        updateCurrentAudioPlayInfo(isCompleted: false, progress: _currentPlayAudioInfo?.progress ?? 0, isPaused: false);
      } else if (state == PlayerState.paused) {
        updateCurrentAudioPlayInfo(isCompleted: false, progress: _currentPlayAudioInfo?.progress ?? 0, isPaused: true);
      } else if (state == PlayerState.stopped) {
        // When receiving this event, _currentPlayAudioInfo may be changed
        // No notifications should be sent at this time
      } else if (state == PlayerState.completed) {
        player!.seek(Duration.zero);
        updateCurrentAudioPlayInfo(isCompleted: true, progress: 1);
        Future.delayed(const Duration(milliseconds: 1500), () async {
          playNextAudio(_audioPlayInfo!.msgID);
        });
      }
    },
    onDone: () {
      console(logs: "onPlayerStateChanged onDone");
    },
    onError: (Object error) {
      console(logs: "onPlayerStateChanged $error");
    },
    cancelOnError: true,
  );
  player!.onPlayerComplete.listen(
    (event) {
      console(logs: "onPlayerComplete");
    },
    onDone: () {
      console(logs: "onPlayerComplete onDone");
    },
    onError: (Object error) {
      console(logs: "onPlayerComplete $error");
    },
    cancelOnError: true,
  );
  player!.onPositionChanged.listen(
    (event) {
      if (_audioPlayInfo != null) {
        if (_audioPlayInfo!.totalSecond != 0 && event.inMilliseconds != 0) {
          console(logs: "onPositionChanged (ms) ${event.inMilliseconds} / ${_audioPlayInfo!.totalSecond * 1000}, isPaused: ${player!.state == PlayerState.paused}, messageID: ${_audioPlayInfo?.msgID}");
          updateCurrentAudioPlayInfo(isCompleted: false, progress: event.inMilliseconds / (_audioPlayInfo!.totalSecond * 1000), isPaused: player!.state == PlayerState.paused);
        }
      }
    },
    onDone: () {
      console(logs: "onPositionChanged onDone");
    },
    onError: (Object error) {
      console(logs: "onPositionChanged $error");
    },
    cancelOnError: true,
  );
  TencentCloudChatDownloadUtils.init();
}