capacitor-audio-engine
Version:
High-quality audio recording Capacitor plugin with native iOS & Android support. Features pause/resume, microphone management, real-time monitoring, audio trimming, and comprehensive mobile audio recording capabilities.
201 lines (199 loc) • 7.56 kB
TypeScript
import type { PluginListenerHandle } from '@capacitor/core';
import { WebPlugin } from '@capacitor/core';
import type { CapacitorAudioEnginePlugin, RecordingStatus, AudioEventName, AudioFileInfo, AudioEventMap, RecordingOptions, MicrophoneStatusResult, AvailableMicrophonesResult, SwitchMicrophoneResult, SwitchMicrophoneOptions, PreloadTracksOptions, PreloadTracksResult, PlaybackInfo, SeekOptions, SkipToIndexOptions } from './definitions';
declare global {
interface BlobEventInit extends EventInit {
data: Blob;
}
interface BlobEvent extends Event {
readonly data: Blob;
}
}
export declare class CapacitorAudioEngineWeb extends WebPlugin implements CapacitorAudioEnginePlugin {
echo(options: {
value: string;
}): Promise<{
value: string;
}>;
/**
* Check if the app has microphone permission.
* @returns Promise that resolves with an object containing the permission status
* @platform web Not supported - returns false
*/
checkPermission(): Promise<{
granted: boolean;
audioPermission?: boolean;
notificationPermission?: boolean;
}>;
/**
* Request microphone permission from the user.
* @returns Promise that resolves with an object containing the permission status
* @platform web Not supported - returns false
*/
requestPermission(): Promise<{
granted: boolean;
audioPermission?: boolean;
notificationPermission?: boolean;
}>;
/**
* Start recording audio from the device's microphone.
* @param options - Recording options
* @returns Promise that resolves when recording starts successfully
* @platform web Not supported
*/
startRecording(_options?: RecordingOptions): Promise<void>;
/**
* Stop the current recording and get the recorded file information.
* @returns Promise that resolves with the recorded audio file details
* @platform web Not supported
*/
stopRecording(): Promise<AudioFileInfo>;
/**
* Pause the current recording.
* @returns Promise that resolves when recording is paused successfully
* @platform web Not supported
*/
pauseRecording(): Promise<void>;
/**
* Resume the current recording if it was previously paused.
* @returns Promise that resolves when recording is resumed successfully
* @platform web Not supported
*/
resumeRecording(): Promise<void>;
/**
* Reset the current recording session by pausing, deleting previous segments,
* and resetting all counters. After calling this method, resumeRecording()
* will behave like starting a fresh recording session.
* @returns Promise that resolves when recording is reset successfully
* @platform web Not supported
*/
resetRecording(): Promise<void>;
/**
* Get the current recording duration.
* @returns Promise that resolves with the current duration in seconds
* @platform web Not supported - returns 0
*/
getDuration(): Promise<{
duration: number;
}>;
/**
* Get the current recording status.
* @returns Promise that resolves with the current recording status
* @platform web Not supported - returns idle
*/
getStatus(): Promise<{
status: RecordingStatus;
isRecording: boolean;
duration: number;
}>;
/**
* Trim an audio file to the specified start and end times.
* @returns Promise that resolves with the trimmed audio file details
* @platform web Not supported
*/
trimAudio({ uri, start, end }: {
uri: string;
start: number;
end: number;
}): Promise<AudioFileInfo>;
/**
* Add a listener for recording events
* @returns A promise that resolves with a handle to the listener
* @platform web Not supported
*/
addListener<T extends AudioEventName>(eventName: T, callback: (event: AudioEventMap[T]) => void): Promise<PluginListenerHandle>;
/**
* Check if microphone is currently being used by another application.
* @returns Promise that resolves with microphone status
* @platform web Not supported
*/
isMicrophoneBusy(): Promise<MicrophoneStatusResult>;
/**
* Get list of available microphones (internal and external).
* @returns Promise that resolves with available microphones
* @platform web Not supported
*/
getAvailableMicrophones(): Promise<AvailableMicrophonesResult>;
/**
* Switch between microphones while keeping recording active.
* @param options - Switch microphone options
* @returns Promise that resolves with switch result
* @platform web Not supported
*/
switchMicrophone(options: SwitchMicrophoneOptions): Promise<SwitchMicrophoneResult>;
/**
* Remove all listeners
* @returns Promise that resolves when all listeners are removed
* @platform web Not supported
*/
removeAllListeners(): Promise<void>;
/**
* Preload audio tracks from URLs and initialize playlist
* @param options - Preload options containing track URLs and preload settings
* @returns Promise that resolves with preload results for each track including load status, mimetype, duration, and file size
* @platform web Not supported
*/
preloadTracks(options: PreloadTracksOptions): Promise<PreloadTracksResult>;
/**
* Start or resume playback of current track
* @returns Promise that resolves when playback starts
* @platform web Not supported
*/
playAudio(): Promise<void>;
/**
* Pause audio playback
* @returns Promise that resolves when playback is paused
* @platform web Not supported
*/
pauseAudio(): Promise<void>;
/**
* Resume audio playback from paused state
* @returns Promise that resolves when playback resumes
* @platform web Not supported
*/
resumeAudio(): Promise<void>;
/**
* Stop audio playback and reset to beginning
* @returns Promise that resolves when playback stops
* @platform web Not supported
*/
stopAudio(): Promise<void>;
/**
* Seek to specific position in current track
* @param options - Seek options with time in seconds
* @returns Promise that resolves when seek completes
* @platform web Not supported
*/
seekAudio(_options: SeekOptions): Promise<void>;
/**
* Skip to next track in playlist
* @returns Promise that resolves when skip completes
* @platform web Not supported
*/
skipToNext(): Promise<void>;
/**
* Skip to previous track in playlist
* @returns Promise that resolves when skip completes
* @platform web Not supported
*/
skipToPrevious(): Promise<void>;
/**
* Skip to specific track index in playlist
* @param options - Options with target track index
* @returns Promise that resolves when skip completes
* @platform web Not supported
*/
skipToIndex(_options: SkipToIndexOptions): Promise<void>;
/**
* Get current playback information
* @returns Promise that resolves with current playback state
* @platform web Not supported
*/
getPlaybackInfo(): Promise<PlaybackInfo>;
/**
* Navigate to the app's permission settings screen.
* @returns Promise that resolves when navigation is initiated
* @platform web Shows alert with instructions to manually open browser settings
*/
openAppSettings(): Promise<void>;
}