MediaLibrary Audio "This file type is not supported yet" on iOS

Please provide the following:

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

I have recorded an audio file using expo-av for both Android and iOS and I am using the following recording options:

    const recordingOptions = {
      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: '.m4a',
        outputFormat: Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_MPEG4AAC,
        audioQuality: Audio.RECORDING_OPTION_IOS_AUDIO_QUALITY_MEDIUM,
        sampleRate: 44100,
        numberOfChannels: 1,
        bitRate: 96400,
        linearPCMBitDepth: 16,
        linearPCMIsBigEndian: false,
        linearPCMIsFloat: false,
      },
     }

I have then used MediaLibrary to save this recorded audio file like in the example below:

 const uri = await this.recording.getURI();
    const asset = await MediaLibrary.createAssetAsync(uri);
    const album = await MediaLibrary.getAlbumAsync("Folder");
    if (album === null) {
      MediaLibrary.createAlbumAsync("Folder", asset, false);
    } else {
      MediaLibrary.addAssetsToAlbumAsync([asset], album.id, false);
    }

On Android this code works fine and saves the .m4a audio file to the correct folder however on iOS I am getting the following error:

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

I tried changing the iOS file extension to .mp3, .caf and others but still ran into the same issue only on iOS.

I have also found two other threads talking about the same issue but there was no followup or response on what is causing the issue or how to fix it before the threads were closed.

https://forums.expo.io/t/audio-not-saved-in-ios-gallery/
https://forums.expo.io/t/audio-recording-not-saving-to-iphone/

Could someone provide some clarification?

Hi, I am the original poster of the second thread you have linked to.

I ended up solving this:

First of all, the iOS emulator does not work with this but if you build the ipa (and test it in testflight) it will work.

To get it to work:

add this to your app.json (I’m not sure if you need all of them):

"ios": {
    "infoPlist": {
        "UISupportsDocumentBrowser": true,
        "UIFileSharingEnabled": true,
        "LSSupportsOpeningDocumentsInPlace": true
    }
}

Also, do not use MediaLibrary or albums, instead use expo-file-system:

this worked for me:

_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());
    options = {
      from: this.recording.getURI(),
      to: FileSystem.documentDirectory + 'a.caf'
    }
    FileSystem.moveAsync(options)
  }

when i opened the files app, i found my recording in a folder.

Thanks for the reply, when you say the iOS emulator does not work with this would you know why? I’m currently testing a lot of functionality that requires this to work and using the expo app to test so it’s a bit annoying If I can’t test during development without building.

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