Unsolved QMediaPlayer::setMedia() file path with spaces will FAIL?
-
the user chooses an mp4 file to play, but that file's path has spaces in it.
okay, why does that fail? the built-in example "video widget" fails to play it
does the path string need to be escaped? how?
-
Just a WAG, but maybe you need to escape it using URL escape formatting where %xx is the hex value of non-alphanumeric chars in the the string so
"hello world" becomes "hello%20world"
-
it is not possible to tell a QUrl how to represent its data when the path is requested in the future, the representation must be determined at the moment the path is requested. it is requested in
AVFMediaPlayerSession::setMedia()
which is deep within the Qt code itself, there is no way to fix this from user space. the request is this:Starting in
AVFMediaPlayerSession
line 592:} else { //Load AVURLAsset //initialize asset using content's URL setURL(m_observer, m_resources.request().url().toString()); }
that lines should read:
} else { //Load AVURLAsset //initialize asset using content's URL setURL(m_observer, m_resources.request().url().toString(QUrl::FullyEncoded)); }
if the line included
QUrl::FullyEncoded
, i believe it would work.does this seem like a bug in Qt to you? is there any way to tell a QUrl how to return the path when someone ELSE calls
toString()
? -
@davecotter said in QMeidaPlayer::setMeida() file path with spaces will FAIL?:
it is requested in AVFMediaPlayerSession::setMedia() which is deep within the Qt code itself, there is no way to fix this from user space. the request is this:
This isn't what you initially asked. You asked how QMediaPLayer::setMedia() handles the URL. As it is a URL, it would make sense that it must be in URL format
-
@davecotter The same file plays when located in a path without spaces?
If so then it is probably a bug and you can post it in Qt bug tracker. -
@Kent-Dorfman perhaps i wasn't as clear as i could have been.
I'm doing this:
QFile qFile("/full path/to/my file.mp4"); // this assert does not fire. ie: the file definitely exists Q_ASSERT(qFile.exists()); QMediaPlayer *playerP(new QMediaPlayer(NULL, QMediaPlayer::VideoSurface)); // i expect Qt to do this correctly QUrl qurl(QUrl::fromLocalFile(qFile.fileName())); playerP->setMedia(qurl);
so you see, i am creating the qUrl correctly. unless you know of some better way to tell qUrl how to be created from a file path?
@jsulm yes with no spaces the file plays fine, i've filed this report and correct me if i'm wrong but this does seem like a critical failure?
if you literally load the example project
Video Widget
that ships WITH Qt Creator, it will fail when you load a movie with a space in it's name. -
@davecotter said in QMeidaPlayer::setMeida() file path with spaces will FAIL?:
this does seem like a critical failure?
Agree