lyricsmanager: parse time string by ourselves

QTime::fromString() can lead a crash when build with icu-enabled
Qt 6.8.0, see QTBUG-130597. Anyway let's workaround this issue
by simply implement it by ourselves.
This commit is contained in:
Gary Wang 2024-10-26 19:38:04 +08:00
parent a3bc60c977
commit b2eb29ab5d
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
2 changed files with 20 additions and 2 deletions

View File

@ -112,8 +112,7 @@ bool LyricsManager::loadLyrics(QString filepath)
QRegularExpressionMatch match = lrcRegex.match(line);
while (match.hasMatch()) {
tagSectionPassed = true;
QTime timestamp(QTime::fromString(match.captured(1), "m:s.zz"));
timestamps.append(timestamp.msecsSinceStartOfDay());
timestamps.append(parseTimeToMilliseconds(match.captured(1)));
currentLrc = match.captured(2);
match = lrcRegex.match(currentLrc);
}
@ -177,6 +176,23 @@ double LyricsManager::maskPercent(int curTimeMs)
return (double)(curTimeMs - currentLyricsTime()) / (m_nextLyricsTime - m_currentLyricsTime);
}
int LyricsManager::parseTimeToMilliseconds(const QString &timeString)
{
QRegularExpression timeRegex(R"((\d{2,3}):(\d{2})\.(\d{2,3}))");
QRegularExpressionMatch match = timeRegex.match(timeString);
if (match.hasMatch()) {
int minutes = match.captured(1).toInt();
int seconds = match.captured(2).toInt();
int milliseconds = match.captured(3).toInt();
return minutes * 60000 + seconds * 1000 + milliseconds;
} else {
qCWarning(lcLyricsParser) << "Invalid time format:" << timeString;
return -1;
}
}
void LyricsManager::reset()
{
m_currentLyricsTime = 0;

View File

@ -25,6 +25,8 @@ public:
QString lyrics(int lineOffset = 0) const;
double maskPercent(int curTimeMs);
static int parseTimeToMilliseconds(const QString& timeString);
protected: