Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _findSong() {
// Audio.setAudioModeAsync()
const {status} = await Audio.requestPermissionsAsync();
console.log('Current Status ' + status);
const recording = new Audio.Recording();
try {
await Audio.setAudioModeAsync({
playsInSilentModeIOS: true,
allowsRecordingIOS: true,
});
const recordOptions = {
android: {
extension: '.m4a',
outputFormat: Audio.RECORDING_OPTION_ANDROID_OUTPUT_FORMAT_MPEG_4,
audioEncoder: Audio.RECORDING_OPTION_ANDROID_AUDIO_ENCODER_AAC,
sampleRate: 44100,
numberOfChannels: 2,
bitRate: 128000,
},
ios: {
extension: '.wav',
}
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: false,
staysActiveInBackground: true,
});
if (this.recording !== null) {
this.recording.setOnRecordingStatusUpdate(null);
this.recording = null;
}
const recording = new Audio.Recording();
await recording.prepareToRecordAsync(this.recordingSettings);
recording.setOnRecordingStatusUpdate(this._updateScreenForRecordingStatus);
this.recording = recording;
await this.recording.startAsync(); // Will call this._updateScreenForRecordingStatus to update the screen.
this.setState({
isLoading: false,
});
}
.then((response) => {
const { status, expires, permissions } = response
if (status === 'granted') {
const newRecording = new Audio.Recording()
newRecording
.prepareToRecordAsync(Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY)
.then((response) => {
return newRecording.startAsync()
})
.then((response) => {
this.setState({
recordingActive: true,
recording: newRecording,
recordAudioVisible: true,
})
})
.catch((error) => console.log(error))
}
})
.catch((error) => {
Permissions.askAsync(Permissions.AUDIO_RECORDING).then(() => {
const recording = new Audio.Recording();
playAll(this.props.sounds, this.props.delay)
.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(() =>
recording.prepareToRecordAsync(
static getInstance () {
if (!RecorderManager.instance) {
RecorderManager.recordInstance = new Audio.Recording()
RecorderManager.instance = new RecorderManager()
}
return RecorderManager.instance
}