我正在使用 Qt5::QMediaPlayer 编写一个视频播放器,以随机播放一些视频,持续时间如下:
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
QMediaPlaylist* playlist = new QMediaPlaylist(&a);
playlist->addMedia(QUrl::fromLocalFile("./Resources/fractal-files/A-060405V4651.WMV"));
playlist->addMedia(QUrl::fromLocalFile("./Resources/fractal-files/E-102604.WMV"));
playlist->addMedia(QUrl::fromLocalFile("./Resources/fractal-files/C-102304.WMV"));
QMediaPlayer* player = new QMediaPlayer(&a);
player->setPlaylist(playlist);
QVideoWidget* videoWidget = new QVideoWidget;
player->setVideoOutput(videoWidget);
player->play();
videoWidget->show();
QTimer* t = new QTimer;
QObject::connect(t, &QTimer::timeout, [&](){
playlist->setCurrentIndex(playlist->nextIndex());
player->play();
videoWidget->setWindowTitle(playlist->currentMedia().canonicalUrl().fileName());
t->start((qrand()%5 + 5)*1000);
});
t->start((qrand()%5 + 5)*1000);
QTimer* t2 = new QTimer;
QObject::connect(t2, &QTimer::timeout, [&](){
player->setPosition(qrand() % player->duration());
videoWidget->setWindowTitle(playlist->currentMedia().canonicalUrl().fileName());
t2->start((qrand()%2 + 2)*1000);
});
t2->start((qrand()%2 + 2)*1000);
return a.exec();
}
有两个问题:
1.什么时候改变位置
player->setPosition(qrand() % player->duration());
有一点延迟(我的客户可以接受,但流畅更好)
2. 当视频源更改为:
playlist->setCurrentIndex(playlist->nextIndex());
player->play();
客户不希望出现持续时间较短的黑屏。他希望效果至少和换位时一样:
player->setPosition(qrand() % player->duration());
在 Windows 上使用 Qt5 更改视频源时,我们可以消除这个黑屏吗?或者我们可以使用其他库/框架来执行此操作(在更改视频源时播放没有黑屏间隙的视频列表)?(在MacOs上,切换流畅)
非常感谢!