react-native-audio-api
Version:
react-native-audio-api provides system for controlling audio in React Native environment compatible with Web Audio API specification
74 lines (72 loc) • 2.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _specs = require("../specs");
var _events = require("../events");
if (global.AudioEventEmitter == null) {
if (!_specs.NativeAudioAPIModule) {
throw new Error(`Failed to install react-native-audio-api: The native module could not be found.`);
}
_specs.NativeAudioAPIModule.install();
}
class AudioManager {
constructor() {
this.audioEventEmitter = new _events.AudioEventEmitter(global.AudioEventEmitter);
}
getDevicePreferredSampleRate() {
return _specs.NativeAudioAPIModule.getDevicePreferredSampleRate();
}
setAudioSessionActivity(enabled) {
return _specs.NativeAudioAPIModule.setAudioSessionActivity(enabled);
}
setAudioSessionOptions(options) {
_specs.NativeAudioAPIModule.setAudioSessionOptions(options.iosCategory ?? '', options.iosMode ?? '', options.iosOptions ?? [], options.iosAllowHaptics ?? false);
}
setLockScreenInfo(info) {
_specs.NativeAudioAPIModule.setLockScreenInfo(info);
}
resetLockScreenInfo() {
_specs.NativeAudioAPIModule.resetLockScreenInfo();
}
observeAudioInterruptions(enabled) {
_specs.NativeAudioAPIModule.observeAudioInterruptions(enabled);
}
/**
* @param enabled - Whether to actively reclaim the session or not
* @experimental more aggressively try to reactivate the audio session during interruptions.
* It is subject to change in the future and might be removed.
*
* In some cases (depends on app session settings and other apps using audio) system may never
* send the `interruption ended` event. This method will check if any other audio is playing
* and try to reactivate the audio session, as soon as there is "silence".
* Although this might change the expected behavior.
*
* Internally method uses `AVAudioSessionSilenceSecondaryAudioHintNotification` as well as
* interval polling to check if other audio is playing.
*/
activelyReclaimSession(enabled) {
_specs.NativeAudioAPIModule.activelyReclaimSession(enabled);
}
observeVolumeChanges(enabled) {
_specs.NativeAudioAPIModule.observeVolumeChanges(enabled);
}
enableRemoteCommand(name, enabled) {
_specs.NativeAudioAPIModule.enableRemoteCommand(name, enabled);
}
addSystemEventListener(name, callback) {
return this.audioEventEmitter.addAudioEventListener(name, callback);
}
async requestRecordingPermissions() {
return _specs.NativeAudioAPIModule.requestRecordingPermissions();
}
async checkRecordingPermissions() {
return _specs.NativeAudioAPIModule.checkRecordingPermissions();
}
async getDevicesInfo() {
return _specs.NativeAudioAPIModule.getDevicesInfo();
}
}
var _default = exports.default = new AudioManager();
//# sourceMappingURL=AudioManager.js.map