mediasfu-reactnative-expo
Version:
mediasfu-reactnative-expo – Expo-managed React Native WebRTC SDK for video conferencing, webinars, live streaming, broadcast, screen sharing, whiteboard, chat, recording, live subtitles, translation, and AI agent rooms on iOS, Android, and web. Prebuilt r
41 lines • 1.18 kB
JavaScript
import { createAudioPlayer } from 'expo-audio';
/**
* Plays a sound from a given URL.
*
* @param {SoundPlayerOptions} options - The options for the sound player.
* @param {string} options.soundUrl - The URL of the sound to play.
*
* @returns {void | Promise<void>}
*
* @example
* ```typescript
* SoundPlayer({ soundUrl: 'https://example.com/sound.mp3' });
* ```
*/
export const SoundPlayer = async ({ soundUrl }) => {
/**
* Plays a sound from the specified URL using expo-audio.
* @function
* @param {string} url - The URL of the sound to play.
*/
let player = null;
try {
player = createAudioPlayer(soundUrl);
// Listen for completion to release the player
player.addListener('playbackStatusUpdate', (status) => {
if (status.didJustFinish && player) {
player.release();
player = null;
}
});
// Play the sound
player.play();
}
catch (error) {
console.warn('SoundPlayer: Failed to play sound', error);
if (player) {
player.release();
}
}
};
//# sourceMappingURL=SoundPlayer.js.map