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',
audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_HIGH,
sampleRate: 8000,
FIREBASE_STORAGE_BUCKET,
FIREBASE_MESSAGING_SENDER_ID,
} = settings
firebase.initializeApp({
apiKey: FIREBASE_API_KEY,
authDomain: FIREBASE_AUTH_DOMAIN,
databaseURL: FIREBASE_DATABASE_URL,
projectId: FIREBASE_PROJECT_ID,
storageBucket: FIREBASE_STORAGE_BUCKET,
messagingSenderId: FIREBASE_MESSAGING_SENDER_ID,
})
const { startLoadingProcess, navigation } = this.props
startLoadingProcess(navigation)
Audio.setAudioModeAsync({
allowsRecordingIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
playThroughEarpieceAndroid: false,
staysActiveInBackground: false,
})
.then((response) => {
// console.log('Audio Mode Setup')
})
.catch((error) => console.log(error))
}
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,
_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);
}
}
.catch((error) => {
console.log(error)
Audio.setAudioModeAsync({
allowsRecordingIOS: false,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
playThroughEarpieceAndroid: false,
staysActiveInBackground: 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
})
)
handleStartAudioRecording = () => {
Audio.setAudioModeAsync({
allowsRecordingIOS: true,
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
playThroughEarpieceAndroid: false,
staysActiveInBackground: false,
})
.then((response) => {
return Permissions.askAsync(Permissions.AUDIO_RECORDING)
})
.then((response) => {
const { status, expires, permissions } = response
if (status === 'granted') {
const newRecording = new Audio.Recording()
newRecording
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 });
})();
}
async _stopPlaybackAndBeginRecording() {
this.setState({
isLoading: true,
});
if (this.sound !== null) {
await this.sound.unloadAsync();
this.sound.setOnPlaybackStatusUpdate(null);
this.sound = null;
}
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);