void MainWindow::on_btnAdd_clicked()
{
QString curPath = QDir::homePath();
QString dlgTitle = "选择音频文件";
QString filter = "音频文件(*.mp3 *.wav *.wma);;mp3文件(*.mp3);;wav文件(*.wav);;wma文件(*.wma);;所有文件(*.*)";
QStringList fileList = QFileDialog::getOpenFileNames(this, dlgTitle, curPath, filter);
if (fileList.count() < 1)
return;
for (int i = 0; i < fileList.count(); i++)
{
QString aFile = fileList.at(i);
QFileInfo fileInfo(aFile);
QString fileName = fileInfo.fileName();
QString filePath = fileInfo.absoluteFilePath();
QString dirPath = fileInfo.absolutePath(); // 该文件所在目录的路径
qDebug() << "添加音频文件:" << fileName << ", 路径:" << filePath << ", 目录:" << dirPath;
ui.listWidget->addItem(fileName);
}
if (player->playbackState() != QMediaPlayer::PlayingState)
ui.listWidget->setCurrentRow(0);
QString url = ui.listWidget->currentItem()->text();
qDebug() << "当前选中文件的URL:" << url;
QDir Dir(url);
QString Url = Dir.absolutePath();
qDebug() << "选中文件所在目录的路径:" << Url;
player->setSource(QUrl::fromLocalFile(Url));
player->play();
}
为什么我添加mp3文件后,文件的时长已经加载出来了,可就是不会播放