Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
darshil-evolution opened this issue Jan 11, 2024 · 4 comments

Comments

@darshil-evolution
Copy link

darshil-evolution commented Jan 11, 2024

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.

  • "react-native-audio-recorder-player": "^3.6.5"
  • "react-native": "0.73.0"
  • IOS

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
Copy link
Contributor

I am having the same problem:

AudioFileObject.cpp:53     CreateDataFile failed

@sooryranga
Copy link
Contributor

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
Copy link
Contributor

Will put out a diff to update Readme.

@sooryranga
Copy link
Contributor

#589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants