Error playing MP3 file

My app got crash while trying to play some of the mp3 file, it still produces sound for like 500 first milliseconds and then went down. Here’s my trace:

Cmdline: com.test.test
pid: 2600, tid: 2640, name: AudioTrack >>> com.test.test<<<
#00 pc 000000000064d80c /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (juce::BufferedInputStream::ensureBuffered()+492)(BuildId: d14de3418acca83c0a7978eed11b10c17a96d925)
#01 pc 0000000000709b58 /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (BuildId:d14de3418acca83c0a7978eed11b10c17a96d925)
#02 pc 000000000064ddd0 /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (BuildId:d14de3418acca83c0a7978eed11b10c17a96d925)
#03 pc 000000000064dc7c /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (juce::BufferedInputStream::read(void*, int)+124) (BuildId: d14de3418acca83c0a7978eed11b10c17a96d925)
#04 pc 00000000005eecf8 /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (juce::MP3Decoder::MP3Stream::decodeNextBlock(float*, float*, int&)+1604) (BuildId: d14de3418acca83c0a7978eed11b10c17a96d925)
#05 pc 00000000005ed7f8 /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (juce::MP3Decoder::MP3Reader::readNextBlock()+104) (BuildId: d14de3418acca83c0a7978eed11b10c17a96d925)
#06 pc 00000000005ede3c /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (juce::MP3Decoder::MP3Reader::readSamples(int* const*, int, int, long long, int)+572) (BuildId: d14de3418acca83c0a7978eed11b10c17a96d925)
#07 pc 000000000057a2c4 /data/app/~~wzc341F6MPIEZhcvDkDA_w==/com.test.test-jTQeIre6pczDGIRcIrKmhA==/base.apk!test.so (juce::AudioFormatReader::read(int* const*, int, long long, int, bool)+400) (BuildId: d14de3418acca83c0a7978eed11b10c17a96d925)

Just some of them can not be played with the above error. Most work well. Thanks in advance

I once spotted a bug in plugin made in JUCE, where it was playing MP3s with Constant bit rate correctly, but MP3s with Variable bit rate weren’t being played correctly. I don’t know if this addresses your issue, but might be worth taking a look.

I’ve looked into the two files, one can be played and the other can’t but they have exactly the same bitrate so i think that’s not the cause

Are you able to provide an example of a broken MP3 file? This would help us to get to the root cause of the problem more quickly. You should be able to send the file to me via direct message if you’d prefer not to link it publicly.

@reuk Here’s the file i got exception from:

@reuk Can you reproduce the error?

A simple program like this doesn’t crash. I also did a bit of fuzz testing on macOS to try to find inputs that would crash, but wasn’t able to find any.

auto* stream = new juce::FileInputStream (juce::File ("lim-dim-902054125.mp3"));

if (auto reader = rawToUniquePtr (juce::MP3AudioFormat{}.createReaderFor (stream, true)))
{
    std::vector<int> floats (reader->numChannels * reader->lengthInSamples);
    std::vector<int*> channels;

    for (auto i = 0; i < reader->numChannels; ++i)
        channels.push_back (floats.data() + i * reader->lengthInSamples);

    reader->read (channels.data(), reader->numChannels, 0, reader->lengthInSamples, true);
}

It looks like you’re running on Android. How are you loading the files? Based on the stack trace, it looks like something’s going wrong with the InputStream that is loading the mp3, so it’d be good to know how this stream was created, and whether it’s reading from a File, or from an AndroidDocument, or from memory (or something else?).

@reuk I’ve tried to do some workaround and it seems like the code itself is not a problem, i’ve addressed a new issue here: [BUG] Strange Mp3 behaviour on different build types

@reuk Btw, here’s how i play my audio:

void AudioEngine::play(const juce::File &audioToPlay) {
    AudioFormatReader *reader = formatManager.createReaderFor(audioToPlay);
    std::unique_ptr<AudioFormatReaderSource> newSource(new AudioFormatReaderSource(reader, false));
    transportSource.setSource(newSource.get(), 0, this, reader->sampleRate);
    transportSource.setPosition(0.0);

    readerSource = std::move(newSource);
    transportSource.start();
}

I didn’t manually create any stream, and yes, the mp3 file is from a juce::File which constructed from a string path (eg: “path/to/the/file.mp3”), all read permission in Android was granted.

Further information to you.