Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _stopRecordingAndEnablePlayback() {
this.setState({
isLoading: true,
});
try {
await this.recording.stopAndUnloadAsync();
} catch (error) {
// Do nothing -- we are already unloaded.
}
const info = await FileSystem.getInfoAsync(this.recording.getURI());
console.log(`FILE INFO: ${JSON.stringify(info)}`);
await Audio.setAudioModeAsync({
allowsRecordingIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
playsInSilentLockedModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: false,
staysActiveInBackground: true,
});
const { sound, status } = await this.recording.createNewLoadedSoundAsync(
{
isLooping: true,
isMuted: this.state.muted,
volume: this.state.volume,
rate: this.state.rate,
shouldCorrectPitch: this.state.shouldCorrectPitch,
},
this._updateScreenForSoundStatus
_applyMode = async () => {
try {
await Audio.setAudioModeAsync({
...this.state.modeToSet,
// iOS values don't matter, this is Android-only selector
allowsRecordingIOS: false,
playsInSilentModeIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
});
this.setState({ setMode: this.state.modeToSet });
} catch (error) {
alert(error.message);
}
}
_applyMode = async () => {
try {
await Audio.setAudioModeAsync({
// ...this.state.modeToSet,
playThroughEarpieceAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
shouldDuckAndroid: true,
// iOS values don't matter, this is Android-only selector
allowsRecordingIOS: false,
playsInSilentModeIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
});
// this.setState({ setMode: this.state.modeToSet });
} catch (error) {
alert(error.message);
}
};
render() {
numberOfChannels = 2,
encodeBitRate = 48000,
format = 'aac',
frameSize,
audioSource = 'auto'
}: any = opts
let options = {
android: Object.assign({}, RecorderManager.RecordingOptions.android, {sampleRate, numberOfChannels, bitRate: encodeBitRate}),
ios: Object.assign({}, RecorderManager.RecordingOptions.ios, {sampleRate, numberOfChannels, bitRate: encodeBitRate})
}
try {
const res = RecorderManager.recordInstance.getStatusAsync()
console.log('res', res)
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
staysActiveInBackground: false,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: true
} as any)
await RecorderManager.recordInstance.prepareToRecordAsync(options)
const res2 = RecorderManager.recordInstance.getStatusAsync()
console.log('res2', res2)
await RecorderManager.recordInstance.startAsync()
} catch (error) {
this.onErrorCallback && this.onErrorCallback({errMsg: error.message})
}
}
componentDidMount() {
Audio.setAudioModeAsync({
allowsRecordingIOS: false,
staysActiveInBackground: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: false
});
(async () => {
await Font.loadAsync({
...MaterialIcons.font,
"cutive-mono-regular": require("./assets/fonts/CutiveMono-Regular.ttf")
});
this.setState({ fontLoaded: true });
})();
}
disabled: !this.state.modeToSet.playsInSilentModeIOS,
value: !this.state.modeToSet.playsInSilentModeIOS ? false : undefined,
})}
{this._renderToggle({
title: 'Stay active in background',
valueName: 'staysActiveInBackground',
disabled: !this.state.modeToSet.playsInSilentModeIOS,
value: !this.state.modeToSet.playsInSilentModeIOS ? false : undefined,
})}
{this._renderModeSelector({
title: 'Mix with others',
value: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
})}
{this._renderModeSelector({
title: 'Do not mix',
value: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
})}
{this._renderModeSelector({
disabled: this.state.modeToSet.playsInSilentModeIOS === false,
title: 'Duck others',
value: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS,
})}
<button disabled="{this._modesEqual(this.state.modeToSet," style="{{" title="Apply changes">
);
}
}</button>
{!Environment.IsIOSRestrictedBuild ? (
{
const newAudioMode = { ...audioMode, staysActiveInBackground: value };
setAudioMode(newAudioMode);
}}
/>
) : null}
{
const newAudioMode = { ...audioMode, interruptionModeIOS: value };
setAudioMode(newAudioMode);
}}
/>
);
}
.then(() =>
Audio.setAudioModeAsync({
staysActiveInBackground: true,
allowsRecordingIOS: true,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
interruptionModeAndroid:
Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
shouldDuckAndroid: true,
playThroughEarpieceAndroid: false
})
)
.then(() =>
Audio.setAudioModeAsync({
staysActiveInBackground: true,
allowsRecordingIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid:
Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: false
})
)