Audio recording not saving to iphone

Please provide the following:

  1. SDK Version: 37.0.3
  2. Platforms(Android/iOS/web/all): iOS

Hi all,

In my app, I am trying to save an audio recording made through the phone microphone.
I am testing it in a physical iphone 7 plus.
_recordAudio() and _stopAudio() are executed with an onPress method of two seperate buttons (omitted here)

Here is the relevant code:

this.recording = null

_stopAudio = async () => {
    Alert.alert("Note", "You are now STOPPED recording.")
    this.setState({isrecording: false})
    await this.recording.stopAndUnloadAsync();
    const info = await FileSystem.getInfoAsync(this.recording.getURI());
    this._playaudio(this.recording.getURI())
    const audiofile = await MediaLibrary.createAssetAsync(this.recording.getURI());
    MediaLibrary.createAlbumAsync('abc-files', audiofile).then(() => {
    }).catch((error) => {
      console.log(error);
    });
  }

  _playaudio = async (uril) => {
    s = {}
    s.uri = uril
    const soundObject = new Audio.Sound();
    await soundObject.loadAsync(s);
    soundObject.playAsync();
  }

  _recordAudio = async () => {
    Alert.alert("Note", "You are now recording.")
    const recording = new Audio.Recording();
    try {
      await Audio.setIsEnabledAsync(true)
      await Audio.setAudioModeAsync({playsInSilentModeIOS: true, allowsRecordingIOS: true})
      await recording.prepareToRecordAsync()
      await recording.startAsync();
      this.setState({isrecording: true})
      this.recording = recording
    // You are now recording!
    } catch (error) {
        console.log("error at recoding:")
        console.log(error)
        this.setState({isrecording: false})
    }
  }

When the _stopAudio() function is executed it is supposed to stop and save the audio to ‘abc-files’ but i am getting the error:

[Unhandled promise rejection: Error: This file type is not supported yet]

This error occurs when i am trying to save the file using MediaLibrary (in _stopAudio() ). The file is a “.caf” file.

Note: _playAudio() works fine and i can hear my recording when it is called from _stopAudio() , so my caf audio file is fine.

The permissions i am asking for is: Permissions.AUDIO_RECORDING and Permissions.CAMERA_ROLL and are being granted before render.
I have checked the variables in this.state at each point and it is as it should be.

This works on Andriod (Pixel 2 and 3)
Any help would be appreciated as i am new to this sort of thing.

1 Like

Faced the same problem! This topic describes a similar situation, but unfortunately unanswered.

I had a look at the expo-media-library on github and tried to see where the error is thrown:

To the best of my understanding, it seems to be here (Line 130):
https://github.com/expo/expo/blob/master/packages/expo-media-library/ios/EXMediaLibrary/EXMediaLibrary.m

  PHAssetMediaType assetType = [EXMediaLibrary _assetTypeForUri:localUri];
  if (assetType == PHAssetMediaTypeUnknown || assetType == PHAssetMediaTypeAudio) {
    reject(@"E_UNSUPPORTED_ASSET", @"This file type is not supported yet", nil);
    return;
  }

So if the Mediatype is unknown or Audio it will throw the error ‘This file type is not supported yet’ ?

Does anyone know why that is, is it an iOS thing?

are you able to solve this?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.