Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
}
_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() {
interface State {
modeToSet: Mode;
setMode: Mode;
}
export default class AudioModeSelector extends React.Component<{}, State> {
readonly state: State = {
modeToSet: {
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
shouldDuckAndroid: true,
playThroughEarpieceAndroid: false,
staysActiveInBackground: false,
},
setMode: {
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
shouldDuckAndroid: true,
playThroughEarpieceAndroid: false,
staysActiveInBackground: false,
},
};
_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 });
.stopAsync()
.then(() => {
return soundObject.unloadAsync()
})
.then(() => {})
.catch((error) => console.log(error))
}
//If id id different than last id play new
if (playingRecording !== _id) {
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(() => {
const newSoundObject = new Audio.Sound()
newSoundObject
.loadAsync({ uri: audio })
.then((response) => {
newSoundObject.setOnPlaybackStatusUpdate((statusData) => {
const { didJustFinish } = statusData
if (didJustFinish) {
this.setState({ playingRecording: '', soundObject: undefined })
}
})
return newSoundObject.playAsync()
})
.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,
})
})
}
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
.prepareToRecordAsync(Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY)
.then((response) => {
return newRecording.startAsync()
})
.then((response) => {
interface Mode {
interruptionModeAndroid: number;
shouldDuckAndroid: boolean;
playThroughEarpieceAndroid: boolean;
staysActiveInBackground: boolean;
}
interface State {
modeToSet: Mode;
setMode: Mode;
}
export default class AudioModeSelector extends React.Component<{}, State> {
readonly state: State = {
modeToSet: {
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
shouldDuckAndroid: true,
playThroughEarpieceAndroid: false,
staysActiveInBackground: false,
},
setMode: {
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
shouldDuckAndroid: true,
playThroughEarpieceAndroid: false,
staysActiveInBackground: false,
},
};
_applyMode = async () => {
try {
await Audio.setAudioModeAsync({
...this.state.modeToSet,
})}
{this._renderToggle({
title: 'Play through earpiece',
valueName: 'playThroughEarpieceAndroid',
})}
{this._renderToggle({
title: 'Stay active in background',
valueName: 'staysActiveInBackground',
})}
{this._renderModeSelector({
title: 'Do not mix',
value: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
})}
{this._renderModeSelector({
title: 'Duck others',
value: Audio.INTERRUPTION_MODE_ANDROID_DUCK_OTHERS,
})}
<button disabled="{this._modesEqual(this.state.modeToSet," style="{{" title="Apply changes">
);
}
}</button>