Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
interface State {
modeToSet: Mode;
setMode: Mode;
}
export default class AudioModeSelector extends React.Component<{}, State> {
readonly state: State = {
modeToSet: {
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
playsInSilentModeIOS: false,
allowsRecordingIOS: false,
staysActiveInBackground: false,
},
setMode: {
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
playsInSilentModeIOS: false,
allowsRecordingIOS: false,
staysActiveInBackground: false,
},
};
_applyMode = async () => {
try {
await Audio.setAudioModeAsync({
...this.state.modeToSet,
// Android values don't matter, this is iOS-only selector
shouldDuckAndroid: false,
interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
playThroughEarpieceAndroid: false,
});
this.setState({ setMode: this.state.modeToSet });
/>
{!Environment.IsIOSRestrictedBuild ? (
{
const newAudioMode = { ...audioMode, staysActiveInBackground: value };
setAudioMode(newAudioMode);
}}
/>
) : null}
{
const newAudioMode = { ...audioMode, interruptionModeIOS: value };
setAudioMode(newAudioMode);
}}
/>
);
import { Audio } from 'expo-av';
import React from 'react';
import { StyleSheet, Switch, View } from 'react-native';
import { BorderlessButton } from 'react-native-gesture-handler';
import AudioPlayer from '../components/AudioPlayer';
import Colors from '../constants/Colors';
import Environment from '../utils/Environment';
import { useAudio, useAudioMode } from '../utils/useAudio';
import { StyledScrollView } from '../components/Views';
import { StyledText } from '../components/Text';
const initialAudioMode = {
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
playsInSilentModeIOS: false,
allowsRecordingIOS: false,
staysActiveInBackground: false,
};
export default function AudioDiagnosticsScreen() {
const [isAudioEnabled, setAudioEnabled] = useAudio();
const [audioMode, setAudioMode] = useAudioMode(initialAudioMode);
return (
Audio Player
})}
{this._renderToggle({
title: 'Allows recording',
valueName: 'allowsRecordingIOS',
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>
interface Mode {
interruptionModeIOS: number;
playsInSilentModeIOS: boolean;
allowsRecordingIOS: boolean;
staysActiveInBackground: boolean;
}
interface State {
modeToSet: Mode;
setMode: Mode;
}
export default class AudioModeSelector extends React.Component<{}, State> {
readonly state: State = {
modeToSet: {
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
playsInSilentModeIOS: false,
allowsRecordingIOS: false,
staysActiveInBackground: false,
},
setMode: {
interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS,
playsInSilentModeIOS: false,
allowsRecordingIOS: false,
staysActiveInBackground: false,
},
};
_applyMode = async () => {
try {
await Audio.setAudioModeAsync({
...this.state.modeToSet,