Loading video using QMediaPlayer and UNC paths

孤者浪人 提交于 2019-12-11 11:51:19

问题


I'm trying to load a video from a network using UNC paths thanks to Qt 5.5 QMediaPlayer. The code snippet is the following one:

projectDirectory = QFileDialog::getExistingDirectory (this,
                                                      tr ("Choose project folder (sensor + video data"),
                                                      QDir::homePath(), QFileDialog::ShowDirsOnly);

QDir dir(projectDirectory);
QStringList test = dir.entryList();
qDebug () << projectDirectory << "contains:" << endl << test;
mediaPlayer.setMedia(QUrl::fromLocalFile(projectDirectory+"/video.mov"));

The code snippet works for a local file but doesn't work when the path begins with //.

Example output:

"//m4800/Partage/111" contains: 
(".", "..", "HandBrake.txt", "sensors.csv", "video.mov")
DirectShowPlayerService::doSetUrlSource: Unresolved error code 80004005

Note that I am able to read the sensors.csv text file and that video.mov has the same permissions.


回答1:


Instead of

mediaPlayer.setMedia(QUrl::fromLocalFile(projectDirectory+"/video.mov"));

remove ::fromLocalFile and try

mediaPlayer.setMedia(QUrl(projectDirectory+"/video.mov"));

This seems to solve the problem. In the codebase I am working on, we have added a check for "//" at the start of the raw path before creating the URL to check it is a UNC path and still use the fromLocalFile if it is not.




回答2:


The DirectShow library does not appear to correctly support UNC paths.

You either have to copy the file to a local temp folder or load the file into a QByteArray and stream from there.

Neither is a great solution and Microsoft depreciated DirectShow in favour of Media Foundation (which has limited playback support at this time).



来源:https://stackoverflow.com/questions/32739198/loading-video-using-qmediaplayer-and-unc-paths

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!