Hello to all. I wrote a player that has a playlist. All functions work perfectly in Windows and Mac OS, but in Mac OS there is one problem. Each time before starting a file, the listbox checks for the presence of files, and if the playlist contains files with the .mp3 extension, then there is a significant delay before playback. If there are 17 files in the playlist, the delay is more than 4 seconds in MacBook Pro 2020 (Ventura OS) and 7 seconds in MacBook Pro 2012 (Catalina OS). The delay increases according to the number of files. On Windows, playback of these same files occurs instantly. Is there a way to avoid such a delay, or does Mac OS not like .mp3 so much?
Below is the file verification code:
void GUI::ListBoxComponent::checkPlaylist()
{
Array<File> files;
AudioFormatManager audioFormatManager;
audioFormatManager.registerBasicFormats();
String audioFormats = audioFormatManager.getWildcardForAllFormats();
#if JUCE_WINDOWS
File::getSpecialLocation (File::userDesktopDirectory).findChildFiles (files, File::findFiles, true, audioFormats);
#else
parseWinPathForMac ();
#endif
totaltimeseconds = 0.0;
if (oscSender.connect (ip, portNumber))
oscSender.send ("/" + ipHome + "/clear", 1);
for(int i = 0; i < songList.size(); i++)
{
File file (filePath.getReference(i));
#if JUCE_MAC
String macPath = filePath.getReference(i);
StringArray arr;
arr.addTokens (macPath, "/", "");
if (arr[3] == "Desktop")
File::getSpecialLocation (File::userDesktopDirectory).findChildFiles (files, File::findFiles, true, audioFormats);
#endif
for (int j = 0; j < files.size(); j++)
{
if (file.getFileName() == files[j].getFileName() && !file.existsAsFile())
{
filePath.set (i, files[j].getFullPathName());
file = filePath.getReference(i);
}
}
AudioTransportSource audioSource;
auto* reader = audioFormatManager.createReaderFor (file);
String a = file.getFileNameWithoutExtension();
String b;
if (reader)
{
auto newSource = std::make_unique<AudioFormatReaderSource> (reader, true);
audioSourceReader.reset (newSource.release());
audioSource.setSource(audioSourceReader.get());
RelativeTime totalLength (audioSource.getLengthInSeconds());
auto hours = ((int) totalLength.inHours()) % 60;
auto minutes = ((int) totalLength.inMinutes()) % 60;
auto seconds = ((int) totalLength.inSeconds()) % 60;
auto totalLengthString = String::formatted ("%02d:%02d", minutes, seconds);
auto totalLengthStringH = String::formatted ("%01d:%02d:%02d", hours, minutes, seconds);
if (audioSource.getLengthInSeconds() < 3600)
{
songDuration.getReference(i) = totalLengthString;
b = totalLengthString;
}
else
{
songDuration.getReference(i) = totalLengthStringH;
b = totalLengthStringH;
}
//============== Full PlayList Time ===============
totaltimeseconds += (double)reader->lengthInSamples / reader->sampleRate;
RelativeTime totalListLength (totaltimeseconds);
auto hoursFull = ((int) totalListLength.inHours()) % 60;
auto minutesFull = ((int) totalListLength.inMinutes()) % 60;
auto secondsFull = ((int) totalListLength.inSeconds()) % 60;
auto totalListLengthString = String::formatted ("%02d:%02d", minutesFull, secondsFull);
auto totalListLengthStringH = String::formatted ("%01d:%02d:%02d", hoursFull, minutesFull, secondsFull);
if (totaltimeseconds < 3600)
infoLblTime = totalListLengthString;
else
infoLblTime = totalListLengthStringH;
//==================================================
if (infoLblTime.isEmpty())
{
infoTextLbl.setText ("0 songs | 00:00", dontSendNotification);
infoLbl.setTooltip ("0 songs | 00:00");
}
else
{
infoLblAmount = static_cast<String>(songList.size());
infoTextLbl.setText (infoLblAmount + " songs | " + infoLblTime, dontSendNotification);
infoLbl.setTooltip (infoLblAmount + " songs | " + infoLblTime);
}
}
else
{
songDuration.getReference(i) = "__:__";
b = "__:__";
}
if (oscSender.connect (ip, portNumber))
oscSender.send ("/" + ipHome + "/fileName", a, b, pointLabel.getReference(i), playingSongIndex);
}
}
If you remove the readability check, then, naturally, the delay disappears. The reason for this is
auto* reader = audioFormatManager.createReaderFor (file);.
Can anyone tell me how to make life easier for the listbox?
Thanks in advance for your valuable advice.
