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:
		@ -112,8 +112,7 @@ bool LyricsManager::loadLyrics(QString filepath)
 | 
				
			|||||||
        QRegularExpressionMatch match = lrcRegex.match(line);
 | 
					        QRegularExpressionMatch match = lrcRegex.match(line);
 | 
				
			||||||
        while (match.hasMatch()) {
 | 
					        while (match.hasMatch()) {
 | 
				
			||||||
            tagSectionPassed = true;
 | 
					            tagSectionPassed = true;
 | 
				
			||||||
            QTime timestamp(QTime::fromString(match.captured(1), "m:s.zz"));
 | 
					            timestamps.append(parseTimeToMilliseconds(match.captured(1)));
 | 
				
			||||||
            timestamps.append(timestamp.msecsSinceStartOfDay());
 | 
					 | 
				
			||||||
            currentLrc = match.captured(2);
 | 
					            currentLrc = match.captured(2);
 | 
				
			||||||
            match = lrcRegex.match(currentLrc);
 | 
					            match = lrcRegex.match(currentLrc);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -177,6 +176,23 @@ double LyricsManager::maskPercent(int curTimeMs)
 | 
				
			|||||||
    return (double)(curTimeMs - currentLyricsTime()) / (m_nextLyricsTime - m_currentLyricsTime);
 | 
					    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()
 | 
					void LyricsManager::reset()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_currentLyricsTime = 0;
 | 
					    m_currentLyricsTime = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,8 @@ public:
 | 
				
			|||||||
    QString lyrics(int lineOffset = 0) const;
 | 
					    QString lyrics(int lineOffset = 0) const;
 | 
				
			||||||
    double maskPercent(int curTimeMs);
 | 
					    double maskPercent(int curTimeMs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static int parseTimeToMilliseconds(const QString& timeString);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user