function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
// @ts-nocheck

import { DeviceEventEmitter, NativeEventEmitter, NativeModules, Platform } from 'react-native';
const {
  RNAudioRecorderPlayerChatVT
} = NativeModules;
export let AudioSourceAndroidType = /*#__PURE__*/function (AudioSourceAndroidType) {
  AudioSourceAndroidType[AudioSourceAndroidType["DEFAULT"] = 0] = "DEFAULT";
  AudioSourceAndroidType[AudioSourceAndroidType["MIC"] = 1] = "MIC";
  AudioSourceAndroidType[AudioSourceAndroidType["VOICE_UPLINK"] = 2] = "VOICE_UPLINK";
  AudioSourceAndroidType[AudioSourceAndroidType["VOICE_DOWNLINK"] = 3] = "VOICE_DOWNLINK";
  AudioSourceAndroidType[AudioSourceAndroidType["VOICE_CALL"] = 4] = "VOICE_CALL";
  AudioSourceAndroidType[AudioSourceAndroidType["CAMCORDER"] = 5] = "CAMCORDER";
  AudioSourceAndroidType[AudioSourceAndroidType["VOICE_RECOGNITION"] = 6] = "VOICE_RECOGNITION";
  AudioSourceAndroidType[AudioSourceAndroidType["VOICE_COMMUNICATION"] = 7] = "VOICE_COMMUNICATION";
  AudioSourceAndroidType[AudioSourceAndroidType["REMOTE_SUBMIX"] = 8] = "REMOTE_SUBMIX";
  AudioSourceAndroidType[AudioSourceAndroidType["UNPROCESSED"] = 9] = "UNPROCESSED";
  AudioSourceAndroidType[AudioSourceAndroidType["RADIO_TUNER"] = 1998] = "RADIO_TUNER";
  AudioSourceAndroidType[AudioSourceAndroidType["HOTWORD"] = 1999] = "HOTWORD";
  return AudioSourceAndroidType;
}({});
export let OutputFormatAndroidType = /*#__PURE__*/function (OutputFormatAndroidType) {
  OutputFormatAndroidType[OutputFormatAndroidType["DEFAULT"] = 0] = "DEFAULT";
  OutputFormatAndroidType[OutputFormatAndroidType["THREE_GPP"] = 1] = "THREE_GPP";
  OutputFormatAndroidType[OutputFormatAndroidType["MPEG_4"] = 2] = "MPEG_4";
  OutputFormatAndroidType[OutputFormatAndroidType["AMR_NB"] = 3] = "AMR_NB";
  OutputFormatAndroidType[OutputFormatAndroidType["AMR_WB"] = 4] = "AMR_WB";
  OutputFormatAndroidType[OutputFormatAndroidType["AAC_ADIF"] = 5] = "AAC_ADIF";
  OutputFormatAndroidType[OutputFormatAndroidType["AAC_ADTS"] = 6] = "AAC_ADTS";
  OutputFormatAndroidType[OutputFormatAndroidType["OUTPUT_FORMAT_RTP_AVP"] = 7] = "OUTPUT_FORMAT_RTP_AVP";
  OutputFormatAndroidType[OutputFormatAndroidType["MPEG_2_TS"] = 8] = "MPEG_2_TS";
  OutputFormatAndroidType[OutputFormatAndroidType["WEBM"] = 9] = "WEBM";
  return OutputFormatAndroidType;
}({});
export let AudioEncoderAndroidType = /*#__PURE__*/function (AudioEncoderAndroidType) {
  AudioEncoderAndroidType[AudioEncoderAndroidType["DEFAULT"] = 0] = "DEFAULT";
  AudioEncoderAndroidType[AudioEncoderAndroidType["AMR_NB"] = 1] = "AMR_NB";
  AudioEncoderAndroidType[AudioEncoderAndroidType["AMR_WB"] = 2] = "AMR_WB";
  AudioEncoderAndroidType[AudioEncoderAndroidType["AAC"] = 3] = "AAC";
  AudioEncoderAndroidType[AudioEncoderAndroidType["HE_AAC"] = 4] = "HE_AAC";
  AudioEncoderAndroidType[AudioEncoderAndroidType["AAC_ELD"] = 5] = "AAC_ELD";
  AudioEncoderAndroidType[AudioEncoderAndroidType["VORBIS"] = 6] = "VORBIS";
  return AudioEncoderAndroidType;
}({});
export let AVEncodingOption = /*#__PURE__*/function (AVEncodingOption) {
  AVEncodingOption["lpcm"] = "lpcm";
  AVEncodingOption["ima4"] = "ima4";
  AVEncodingOption["aac"] = "aac";
  AVEncodingOption["MAC3"] = "MAC3";
  AVEncodingOption["MAC6"] = "MAC6";
  AVEncodingOption["ulaw"] = "ulaw";
  AVEncodingOption["alaw"] = "alaw";
  AVEncodingOption["mp1"] = "mp1";
  AVEncodingOption["mp2"] = "mp2";
  AVEncodingOption["mp4"] = "mp4";
  AVEncodingOption["alac"] = "alac";
  AVEncodingOption["amr"] = "amr";
  AVEncodingOption["flac"] = "flac";
  AVEncodingOption["opus"] = "opus";
  return AVEncodingOption;
}({});
export let AVModeIOSOption = /*#__PURE__*/function (AVModeIOSOption) {
  AVModeIOSOption["gamechat"] = "gamechat";
  AVModeIOSOption["measurement"] = "measurement";
  AVModeIOSOption["movieplayback"] = "movieplayback";
  AVModeIOSOption["spokenaudio"] = "spokenaudio";
  AVModeIOSOption["videochat"] = "videochat";
  AVModeIOSOption["videorecording"] = "videorecording";
  AVModeIOSOption["voicechat"] = "voicechat";
  AVModeIOSOption["voiceprompt"] = "voiceprompt";
  return AVModeIOSOption;
}({});
export let AVEncoderAudioQualityIOSType = /*#__PURE__*/function (AVEncoderAudioQualityIOSType) {
  AVEncoderAudioQualityIOSType[AVEncoderAudioQualityIOSType["min"] = 0] = "min";
  AVEncoderAudioQualityIOSType[AVEncoderAudioQualityIOSType["low"] = 32] = "low";
  AVEncoderAudioQualityIOSType[AVEncoderAudioQualityIOSType["medium"] = 64] = "medium";
  AVEncoderAudioQualityIOSType[AVEncoderAudioQualityIOSType["high"] = 96] = "high";
  AVEncoderAudioQualityIOSType[AVEncoderAudioQualityIOSType["max"] = 127] = "max";
  return AVEncoderAudioQualityIOSType;
}({});
export let AVLinearPCMBitDepthKeyIOSType = /*#__PURE__*/function (AVLinearPCMBitDepthKeyIOSType) {
  AVLinearPCMBitDepthKeyIOSType[AVLinearPCMBitDepthKeyIOSType["bit8"] = 8] = "bit8";
  AVLinearPCMBitDepthKeyIOSType[AVLinearPCMBitDepthKeyIOSType["bit16"] = 16] = "bit16";
  AVLinearPCMBitDepthKeyIOSType[AVLinearPCMBitDepthKeyIOSType["bit24"] = 24] = "bit24";
  AVLinearPCMBitDepthKeyIOSType[AVLinearPCMBitDepthKeyIOSType["bit32"] = 32] = "bit32";
  return AVLinearPCMBitDepthKeyIOSType;
}({});
const pad = num => {
  return ('0' + num).slice(-2);
};
class AudioRecorderPlayer {
  constructor() {
    _defineProperty(this, "_isRecording", void 0);
    _defineProperty(this, "_isPlaying", void 0);
    _defineProperty(this, "_hasPaused", void 0);
    _defineProperty(this, "_hasPausedRecord", void 0);
    _defineProperty(this, "_recorderSubscription", void 0);
    _defineProperty(this, "_playerSubscription", void 0);
    _defineProperty(this, "_playerCallback", void 0);
    _defineProperty(this, "mmss", secs => {
      let minutes = Math.floor(secs / 60);
      secs = secs % 60;
      minutes = minutes % 60;
      return pad(minutes) + ':' + pad(secs);
    });
    _defineProperty(this, "mmssss", milisecs => {
      const secs = Math.floor(milisecs / 1000);
      const minutes = Math.floor(secs / 60);
      const seconds = secs % 60;
      // const miliseconds = Math.floor((milisecs % 1000) / 10);

      // return pad(minutes) + ':' + pad(seconds) + ':' + pad(miliseconds);
      return pad(minutes) + ':' + pad(seconds);
    });
    /**
     * Set listerner from native module for recorder.
     * @returns {callBack((e: RecordBackType): void)}
     */
    _defineProperty(this, "addRecordBackListener", callback => {
      if (Platform.OS === 'android') {
        this._recorderSubscription = DeviceEventEmitter.addListener('rn-recordback', callback);
      } else {
        const myModuleEvt = new NativeEventEmitter(RNAudioRecorderPlayerChatVT);
        this._recorderSubscription = myModuleEvt.addListener('rn-recordback', callback);
      }
    });
    /**
     * Remove listener for recorder.
     * @returns {void}
     */
    _defineProperty(this, "removeRecordBackListener", () => {
      if (this._recorderSubscription) {
        this._recorderSubscription.remove();
        this._recorderSubscription = null;
      }
    });
    /**
     * Set listener from native module for player.
     * @returns {callBack((e: PlayBackType): void)}
     */
    _defineProperty(this, "addPlayBackListener", callback => {
      this._playerCallback = callback;
    });
    /**
     * remove listener for player.
     * @returns {void}
     */
    _defineProperty(this, "removePlayBackListener", () => {
      this._playerCallback = null;
    });
    /**
     * start recording with param.
     * @param {string} uri audio uri.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "startRecorder", async (uri, audioSets, meteringEnabled) => {
      if (!this._isRecording) {
        this._isRecording = true;
        if (!uri) uri = 'DEFAULT';
        return RNAudioRecorderPlayerChatVT.startRecorder(uri, audioSets, meteringEnabled !== null && meteringEnabled !== void 0 ? meteringEnabled : false);
      }
      return 'Already recording';
    });
    /**
     * Pause recording.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "pauseRecorder", async () => {
      if (!this._hasPausedRecord) {
        this._hasPausedRecord = true;
        return RNAudioRecorderPlayerChatVT.pauseRecorder();
      }
      return 'Already paused recording.';
    });
    /**
     * Resume recording.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "resumeRecorder", async () => {
      if (this._hasPausedRecord) {
        this._hasPausedRecord = false;
        return RNAudioRecorderPlayerChatVT.resumeRecorder();
      }
      return 'Currently recording.';
    });
    /**
     * stop recording.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "stopRecorder", async () => {
      if (this._isRecording) {
        this._isRecording = false;
        this._hasPausedRecord = false;
        return RNAudioRecorderPlayerChatVT.stopRecorder();
      }
      return 'Already stopped';
    });
    /**
     * Resume playing.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "resumePlayer", async () => {
      if (!this._isPlaying) {
        return 'No audio playing';
      }
      if (this._hasPaused) {
        this._hasPaused = false;
        return RNAudioRecorderPlayerChatVT.resumePlayer();
      }
      return 'Already playing';
    });
    _defineProperty(this, "playerCallback", event => {
      if (this._playerCallback) {
        this._playerCallback(event);
      }
      if (event.currentPosition === event.duration) {
        this.stopPlayer();
      }
    });
    // @ts-ignore
    /**
     * Start playing with param.
     * @param {string} uri audio uri.
     * @param {Record<string, string>} httpHeaders Set of http headers.
     * @returns {Promise<string>}
     */
    // @ts-ignore
    _defineProperty(this, "startPlayer", async (uri, httpHeaders) => {
      if (!uri) {
        uri = 'DEFAULT';
      }
      if (!this._playerSubscription) {
        if (Platform.OS === 'android') {
          this._playerSubscription = DeviceEventEmitter.addListener('rn-playback', this.playerCallback);
        } else {
          const myModuleEvt = new NativeEventEmitter(RNAudioRecorderPlayerChatVT);
          this._playerSubscription = myModuleEvt.addListener('rn-playback', this.playerCallback);
        }
      }
      if (!this._isPlaying || this._hasPaused) {
        this._isPlaying = true;
        this._hasPaused = false;
        return RNAudioRecorderPlayerChatVT.startPlayer(uri, httpHeaders);
      }
    });
    /**
     * Stop playing.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "stopPlayer", async () => {
      if (this._isPlaying) {
        this._isPlaying = false;
        this._hasPaused = false;
        return RNAudioRecorderPlayerChatVT.stopPlayer();
      }
      return 'Already stopped playing';
    });
    /**
     * Pause playing.
     * @returns {Promise<string>}
     */
    // @ts-ignore
    _defineProperty(this, "pausePlayer", async () => {
      if (!this._isPlaying) {
        return 'No audio playing';
      }
      if (!this._hasPaused) {
        this._hasPaused = true;
        return RNAudioRecorderPlayerChatVT.pausePlayer();
      }
    });
    /**
     * Seek to.
     * @param {number} time position seek to in millisecond.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "seekToPlayer", async time => {
      return RNAudioRecorderPlayerChatVT.seekToPlayer(time);
    });
    /**
     * Set volume.
     * @param {number} setVolume set volume.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "setVolume", async volume => {
      if (volume < 0 || volume > 1) {
        throw new Error('Value of volume should be between 0.0 to 1.0');
      }
      return RNAudioRecorderPlayerChatVT.setVolume(volume);
    });
    /**
     * Set subscription duration. Default is 0.5.
     * @param {number} sec subscription callback duration in seconds.
     * @returns {Promise<string>}
     */
    _defineProperty(this, "setSubscriptionDuration", async sec => {
      return RNAudioRecorderPlayerChatVT.setSubscriptionDuration(sec);
    });
  }
}
export default AudioRecorderPlayer;
//# sourceMappingURL=index.android.js.map