@scr2em/capacitor-plugin-recorder
v0.0.8
Published
record audios and play them back
Readme
capacitor-plugin-recorder
ee
Install
npm install capacitor-plugin-recorder
npx cap syncAPI
requestPermission()checkPermission()startRecord(...)stopRecord(...)pauseRecord(...)resumeRecord(...)preparePlay(...)play(...)pausePlay(...)resumePlay(...)stopPlay(...)seekTo(...)getPlaybackStatus(...)getRecordingStatus(...)destroyRecorder(...)destroyPlayer(...)addListener('recordingStatusChange', ...)addListener('playbackStatusChange', ...)removeAllListeners()- Interfaces
- Type Aliases
requestPermission()
requestPermission() => Promise<PermissionStatus>Request microphone permission
Returns: Promise<PermissionStatus>
checkPermission()
checkPermission() => Promise<PermissionStatus>Check current permission status
Returns: Promise<PermissionStatus>
startRecord(...)
startRecord(options?: StartRecordOptions | undefined) => Promise<StartRecordResult>Start recording audio. Returns a recorderId that must be used for all subsequent operations on this recorder.
| Param | Type |
| ------------- | ----------------------------------------------------------------- |
| options | StartRecordOptions |
Returns: Promise<StartRecordResult>
stopRecord(...)
stopRecord(options: RecorderOptions) => Promise<StopRecordResult>Stop recording and return the recorded file path
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | RecorderOptions |
Returns: Promise<StopRecordResult>
pauseRecord(...)
pauseRecord(options: RecorderOptions) => Promise<void>Pause the current recording
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | RecorderOptions |
resumeRecord(...)
resumeRecord(options: RecorderOptions) => Promise<void>Resume a paused recording
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | RecorderOptions |
preparePlay(...)
preparePlay(options: PlayOptions) => Promise<PreparePlayResult>Prepare an audio file for playback (loads metadata without playing). Returns a playerId that must be used for all subsequent operations on this player.
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | PlayOptions |
Returns: Promise<PreparePlayResult>
play(...)
play(options: PlayerOptions) => Promise<void>Start playing an audio file
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | PlayerOptions |
pausePlay(...)
pausePlay(options: PlayerOptions) => Promise<void>Pause audio playback
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | PlayerOptions |
resumePlay(...)
resumePlay(options: PlayerOptions) => Promise<void>Resume paused audio playback
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | PlayerOptions |
stopPlay(...)
stopPlay(options: PlayerOptions) => Promise<void>Stop audio playback
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | PlayerOptions |
seekTo(...)
seekTo(options: SeekOptions) => Promise<void>Seek to a specific position in the audio
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | SeekOptions |
getPlaybackStatus(...)
getPlaybackStatus(options: PlayerOptions) => Promise<PlaybackStatusChangeEvent>Get current playback status for a specific player
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | PlayerOptions |
Returns: Promise<PlaybackStatusChangeEvent>
getRecordingStatus(...)
getRecordingStatus(options: RecorderOptions) => Promise<RecordingStatusChangeEvent>Get current recording status for a specific recorder
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | RecorderOptions |
Returns: Promise<RecordingStatusChangeEvent>
destroyRecorder(...)
destroyRecorder(options: RecorderOptions) => Promise<void>Destroy a recorder and release its resources
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options | RecorderOptions |
destroyPlayer(...)
destroyPlayer(options: PlayerOptions) => Promise<void>Destroy a player and release its resources
| Param | Type |
| ------------- | ------------------------------------------------------- |
| options | PlayerOptions |
addListener('recordingStatusChange', ...)
addListener(eventName: 'recordingStatusChange', listenerFunc: (event: RecordingStatusChangeEvent) => void) => Promise<PluginListenerHandle>Listen for recording status changes
| Param | Type |
| ------------------ | ----------------------------------------------------------------------------------------------------- |
| eventName | 'recordingStatusChange' |
| listenerFunc | (event: RecordingStatusChangeEvent) => void |
Returns: Promise<PluginListenerHandle>
addListener('playbackStatusChange', ...)
addListener(eventName: 'playbackStatusChange', listenerFunc: (event: PlaybackStatusChangeEvent) => void) => Promise<PluginListenerHandle>Listen for playback status changes (includes playerId to identify which player)
| Param | Type |
| ------------------ | --------------------------------------------------------------------------------------------------- |
| eventName | 'playbackStatusChange' |
| listenerFunc | (event: PlaybackStatusChangeEvent) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>Remove all listeners
Interfaces
PermissionStatus
| Prop | Type |
| ---------------- | ---------------------------------------------- |
| microphone | 'granted' | 'denied' | 'prompt' |
StartRecordResult
| Prop | Type | Description |
| ---------------- | ------------------- | -------------------------------------------- |
| recorderId | string | Unique identifier for this recorder instance |
StartRecordOptions
| Prop | Type | Description |
| ---------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| path | string | Optional relative path for the recording (including extension), relative to the app's data directory. If not provided, a default filename will be used. |
StopRecordResult
| Prop | Type | Description |
| ---------------- | ------------------- | ----------------------------------------- |
| recorderId | string | The recorder ID |
| path | string | Path to the recorded file |
| duration | number | Duration of the recording in milliseconds |
RecorderOptions
| Prop | Type | Description |
| ---------------- | ------------------- | ----------------------------------------- |
| recorderId | string | The recorder ID returned from startRecord |
PreparePlayResult
| Prop | Type | Description |
| -------------- | ------------------- | ------------------------------------------ |
| playerId | string | Unique identifier for this player instance |
| duration | number | Duration of the audio in milliseconds |
PlayOptions
| Prop | Type | Description |
| ---------- | ------------------- | ------------------------------------------------------------------------------ |
| path | string | Relative path to the audio file to play (relative to the app's data directory) |
PlayerOptions
| Prop | Type | Description |
| -------------- | ------------------- | --------------------------------------- |
| playerId | string | The player ID returned from preparePlay |
SeekOptions
| Prop | Type | Description |
| -------------- | ------------------- | --------------------------------------- |
| playerId | string | The player ID returned from preparePlay |
| position | number | Position to seek to in milliseconds |
PlaybackStatusChangeEvent
| Prop | Type | Description |
| --------------------- | --------------------------------------------------------- | ------------------------------------------- |
| playerId | string | The player ID this event belongs to |
| status | PlaybackStatus | |
| currentPosition | number | Current playback position in milliseconds |
| duration | number | Total duration of the audio in milliseconds |
RecordingStatusChangeEvent
| Prop | Type | Description |
| ---------------- | ----------------------------------------------------------- | ------------------------------------------ |
| recorderId | string | The recorder ID this event belongs to |
| status | RecordingStatus | |
| duration | number | Current recording duration in milliseconds |
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
Type Aliases
PlaybackStatus
'playing' | 'paused' | 'stopped' | 'ended'
RecordingStatus
'recording' | 'paused' | 'stopped'
