问题
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