hyochan / react-native-audio-recorder-player

react-native native module for audio recorder and player.
MIT License
709 stars 212 forks source link

Facing issue in iOS `CreateDataFile failed` and `Couldn't create a new audio file object` #578

Closed darshil-evolution closed 3 weeks ago

darshil-evolution commented 8 months ago

Not able to recored the audio in iOS. Getting errors in xcode consloe CreateDataFile failed and Couldn't create a new audio file object. In android working perfect. When I am giving just name in path like audioFile.acc it's working fine but when using RNFS path that time getting error.

Expected behavior: I want to store audio on RNFS.DocumentDirectoryPath Actual behavior: Error starting recording: [Error: Error occured during initiating recorder]

  const currentDate = generateUniqueString().toString();
    const name = `${currentDate}.acc`;
const path = RNFS.DocumentDirectoryPath + `/${name}`;
await audioRecorderPlayer.startRecorder(path, audioSet, meteringEnabled);
sooryranga commented 7 months ago

I am having the same problem:

AudioFileObject.cpp:53     CreateDataFile failed
sooryranga commented 7 months ago

Figured it out, if you want specific file in IOS: you need to append file://

So the path would be:

const path = `file://${RNFS.DocumentDirectoryPath}/${name}`;

From code:

    func setAudioFileURL(path: String) {
        if (path == "DEFAULT") {
            let cachesDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
            audioFileURL = cachesDirectory.appendingPathComponent("sound.m4a")
        } else if (path.hasPrefix("http://") || path.hasPrefix("https://") || path.hasPrefix("file://")) {
            audioFileURL = URL(string: path)
        } else {
            let cachesDirectory = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
            audioFileURL = cachesDirectory.appendingPathComponent(path)
        }
    }
sooryranga commented 7 months ago

Will put out a diff to update Readme.

sooryranga commented 7 months ago

https://github.com/hyochan/react-native-audio-recorder-player/pull/589