Load BinaryData and play it back

Hi Everybody,
I’ve been trying for a week now to load binary datas to my plugin and play thoose back.
Doing the “usual” way:

AudioFormatManager formatManager;

MemoryInputStream* input = new MemoryInputStream (BinaryData::guitar_wav, BinaryData::guitar_wavSize, false);
AudioFormatReader* reader = formatManager.createReaderFor (input);

wasn’t working here (“new” kept being highlighted and “createReaderFor” wasn’t couldn’t be recognized )

i found that method wich seems to work for me as virtual studio seems to show no errors:


juce::AudioFormatManager formatManager;
void HelloSamplerAudioProcessor::loadFile();



void HelloSamplerAudioProcessor::loadFile()
auto input = std::make_uniquejuce::MemoryInputStream(BinaryData::sec1_wav, BinaryData::sec1_wavSize, false);
auto* reader = formatManager.createReaderFor(std::move(input));
if (reader != nullptr);


But still doesn’t play the file… would anybody know what i do wrong??

and yeah until now there was no sound at all but with this method there s a clip going on once i launch and close

The “usual” way didn’t work because createReaderFor() expects either a File or std::unique_ptr<InputStream>. You’re trying to pass in a raw MemoryInputStream pointer, instead of a unique_ptr one.

auto input = std::make_uniquejuce::MemoryInputStream(BinaryData::sec1_wav, BinaryData::sec1_wavSize, false);

In this line it looks like you forgot the <> braces around juce::MemoryInputStream. Or is that a typo? If you add them, that code should load the wav from the BinaryData correctly.

Also, the code you provided has no way to play the audio back, just load it. Where’s your code that does this?

Thanks a lot Jojo! oh ok that makes sense then… now that you told me what i was doing wrong at loading the file i can focuse finding the way to play it :wink:
(i thought doing that line of code was going to be loading and playing the file, i’m really new at learning juce and coding )

Glad I could help!

1 Like