我正在使用c ++中的phonon库构建一个音乐播放器。 这是用于提取歌曲的元信息的代码:
void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */)
{
if (newState == Phonon::ErrorState) {
QMessageBox::warning(this, tr("Error opening files"),
metaInformationResolver->errorString());
while (!sources.isEmpty() &&
!(sources.takeLast() == metaInformationResolver->currentSource())) {} /* loop */;
return;
}
if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
return;
if (metaInformationResolver->currentSource().type() == Phonon::MediaSource::Invalid)
return;
QMap<QString, QString> metaData = metaInformationResolver->metaData();
QString title = metaData.value("TITLE");
if (title == "")
title = metaInformationResolver->currentSource().fileName();
QTableWidgetItem *titleItem = new QTableWidgetItem(title);
titleItem->setFlags(titleItem->flags() ^ Qt::ItemIsEditable);
QTableWidgetItem *artistItem = new QTableWidgetItem(metaData.value("ARTIST"));
artistItem->setFlags(artistItem->flags() ^ Qt::ItemIsEditable);
QTableWidgetItem *albumItem = new QTableWidgetItem(metaData.value("ALBUM"));
albumItem->setFlags(albumItem->flags() ^ Qt::ItemIsEditable);
QTableWidgetItem *yearItem = new QTableWidgetItem(metaData.value("DATE"));
yearItem->setFlags(yearItem->flags() ^ Qt::ItemIsEditable);
int currentRow = musicTable->rowCount();
musicTable->insertRow(currentRow);
musicTable->setItem(currentRow, 0, titleItem);
musicTable->setItem(currentRow, 1, artistItem);
musicTable->setItem(currentRow, 2, albumItem);
musicTable->setItem(currentRow, 3, yearItem);
if (musicTable->selectedItems().isEmpty()) {
musicTable->selectRow(0);
mediaObject->setCurrentSource(metaInformationResolver->currentSource());
}
Phonon::MediaSource source = metaInformationResolver->currentSource();
int index = sources.indexOf(metaInformationResolver->currentSource()) + 1;
if (sources.size() > index) {
metaInformationResolver->setCurrentSource(sources.at(index));
}
else {
musicTable->resizeColumnsToContents();
if (musicTable->columnWidth(0) > 300)
musicTable->setColumnWidth(0, 300);
}
}
然而,这无法提取信息。 如果要发布更多代码,请告诉我。