Plugin EcosystemHardware & Sensors
Audio
Native audio playback and recording capabilities.
Audio Plugin
The Audio plugin gives you granular control over the device's native audio hardware. Whether you need to play background music, trigger sound effects, or record voice memos, this plugin has you covered.
Installation
npm install @easycord/plugin-audioAPI Reference
play(options: PlayOptions)
Plays an audio file from a local path or remote URL.
startRecording(options?: RecordOptions)
Begins recording audio from the device microphone.
Example Usage
import { useState } from 'react';
import { Audio } from '@easycord/plugin-audio';
export default function AudioRecorder() {
const [isRecording, setIsRecording] = useState(false);
const toggleRecording = async () => {
if (isRecording) {
const result = await Audio.stopRecording();
console.log('Saved to:', result.path);
setIsRecording(false);
} else {
await Audio.startRecording({ format: 'aac' });
setIsRecording(true);
}
};
return (
<div className="p-4">
<button
onClick={toggleRecording}
className={`px-4 py-2 rounded text-white ${isRecording ? 'bg-red-600' : 'bg-blue-600'}`}
>
{isRecording ? 'Stop Recording' : 'Start Recording'}
</button>
</div>
);
}