[solved] setLooping()

i have an audioplayer - it plays fine.

But I want it to loop. but the setLooping() method doesn’t seem to work

any guidance

void playAudio()
{
	auto* reader = formatManager.createReaderFor(File(start.filename));

	if (reader != nullptr)
	{
		std::unique_ptr<AudioFormatReaderSource> newSource(new AudioFormatReaderSource(reader, true));
		transportSource.setSource(newSource.get(), 0, nullptr, reader->sampleRate);
		transportSource.setLooping(start.isLooping); // start.isLooping = true
		bool testLooping = transportSource.isLooping(); // always false
		transportSource.start();
		readerSource.reset(newSource.release());

	}
}

AudioFormatManager formatManager;
std::unique_ptr<AudioFormatReaderSource> readerSource;
AudioTransportSource transportSource;

Its, OK, I solved this.

I realised that I had to set the AudioFormatReaderSource looping method so it is inherited!

		std::unique_ptr<AudioFormatReaderSource> newSource(new AudioFormatReaderSource(reader, true));
		newSource->setLooping(start.isLooping); // the fix
		transportSource.setSource(newSource.get(), 0, nullptr, reader->sampleRate);
		transportSource.start();
		readerSource.reset(newSource.release());
2 Likes