我是Qt和C ++的初学者,并制作了示例媒体播放器。我只想使用QMediaplaylist类创建一个播放列表。
我只想在单击图标时弹出一个窗口,我可以选择多个视频文件并将这些文件附加到QMediaplaylist中。
我已经完成了多项选择部分。但是我不知道如何用QMediaPlaylist追加这些文件。
playlist = new QMediaPlaylist(player);
QStringList filenames = QFileDialog::getOpenFileNames(this,"Open a File","","Video File(*.*)");
playlist->addMedia(filenames); //error has occurred in this line
player->setPlaylist(playlist);
on_actionPlay_triggered();
语义问题
error:no matching member function for call to 'addMedia"
qmediaplaylist.h:90:10:note:candidate function not viable:no known
conversion from 'QStringList' to const QMediaContent' for 1st argument
qmediaplaylist.h:91:10:note:candidate function not viable:no known
conversion from 'QStringList' to 'const QList<QMediaContent>'for 1st
argument
答案 0 :(得分:0)
您必须使用QMediaContent
来转换QUrl::fromLocalFile()
中的每个路径:
playlist = new QMediaPlaylist(player);
QStringList filenames = QFileDialog::getOpenFileNames(this, "Open a File","","Video File(*.*)");
for(const QString & filename: filenames){
playlist->addMedia(QMediaContent(QUrl::fromLocalFile(filename)));
}
player->setPlaylist(playlist);