How to use the expo-av.Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX function in expo-av

To help you get started, we’ve selected a few expo-av examples, based on popular ways it is used in public projects.

github expo / audio-recording-example / App.js View on Github external
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
github expo / expo / apps / native-component-list / src / screens / AV / AudioModeSelector.android.tsx View on Github external
_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);
    }
  }
github EvanBacon / Instagram / App.js View on Github external
_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() {
github NervJS / taro / packages / taro-rn / src / api / media / record.ts View on Github external
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})
    }
  }
github expo / playlist-example / App.js View on Github external
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 });
    })();
  }
github expo / expo / apps / native-component-list / src / screens / AV / AudioModeSelector.ios.tsx View on Github external
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
          title="Apply changes"
          onPress={this._applyMode}
          style={{ marginTop: 10 }}
          disabled={this._modesEqual(this.state.modeToSet, this.state.setMode)}
        />
      </View>
    );
  }
}
github expo / expo / home / screens / AudioDiagnosticsScreen.tsx View on Github external
{!Environment.IsIOSRestrictedBuild ? (
        <AudioOptionSwitch
          title="Continues Playing in Background"
          value={audioMode.staysActiveInBackground}
          disabled={!isAudioEnabled || !audioMode.playsInSilentModeIOS}
          onValueChange={value => {
            const newAudioMode = { ...audioMode, staysActiveInBackground: value };
            setAudioMode(newAudioMode);
          }}
        />
      ) : null}
      <AudioOptionSelector
        title="Interruption Mode"
        items={[
          { name: 'Mix with Other Apps', value: Audio.INTERRUPTION_MODE_IOS_MIX_WITH_OTHERS },
          { name: 'Do Not Mix', value: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX },
          {
            name: 'Duck Other Apps',
            value: Audio.INTERRUPTION_MODE_IOS_DUCK_OTHERS,
            disabled: !audioMode.playsInSilentModeIOS,
          },
        ]}
        disabled={!isAudioEnabled}
        selectedValue={audioMode.interruptionModeIOS}
        onSelect={value => {
          const newAudioMode = { ...audioMode, interruptionModeIOS: value };
          setAudioMode(newAudioMode);
        }}
      />
    </StyledScrollView>
  );
}
github serlo / serlo-abc / src / components / helpers / PlaySounds.tsx View on Github external
.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
            })
          )
github serlo / serlo-abc / src / components / helpers / PlaySounds.tsx View on Github external
.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
            })
          )