AudioFormatWriter on iOS using URL

If I want to write a WAV file from a iOS App to a shared folder, File can’t be used, URL must be used instead. So, what I’m doing is:

    WavAudioFormat format;
    std::unique_ptr<AudioFormatWriter> writer;
    writer.reset(format.createWriterFor(new FileOutputStream(url.getLocalFile()), getSampleRate(), 2, 16, {}, 0));

Unfortunately this doesn’t work on shared folders, write a 0-byte file. Only works for the App’s local storage (for which File still works).

This doesn’t work either (compiles but crashes):

    WavAudioFormat format;
    auto writer = format.createWriterFor(url.createOutputStream().get(), getSampleRate(), 2, 16, {}, 0);

Any help?

Hey ZioGuido, you dumbarse! Don’t you know you have to use std::unique_ptr::release()?
Here’s the solution:

    WavAudioFormat format;
    std::unique_ptr<AudioFormatWriter> writer;
    writer.reset(format.createWriterFor(url.createOutputStream().release(), getSampleRate(), 2, 16, {}, 0));

Don’t thank me. :joy: