Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMediaPlayer::setMedia() file path with spaces will FAIL?
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer::setMedia() file path with spaces will FAIL?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 869 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by aha_1980
    #1

    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?

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      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"

      1 Reply Last reply
      0
      • D Offline
        D Offline
        davecotter
        wrote on last edited by
        #3

        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() ?

        jsulmJ 1 Reply Last reply
        0
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0
          • D davecotter

            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() ?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              davecotter
              wrote on last edited by davecotter
              #6

              @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.

              jsulmJ 1 Reply Last reply
              0
              • D davecotter

                @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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @davecotter said in QMeidaPlayer::setMeida() file path with spaces will FAIL?:

                this does seem like a critical failure?

                Agree

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved