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 on background thread?
Forum Updated to NodeBB v4.3 + New Features

QMediaPlayer on background thread?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 874 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
    #1

    If i ONLY want to get the dimensions and duration of a video, can i instantiate QMediaPlayer on a background thread and start it playing it (silently, invisibly) so i can get the signals about meta data changing and cache the info it returns (dimensions / duration) ?

    or must i do all this on the main thread?

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

      so the answer is "no you can't do it on a background thread. it must be done on the main UI thread"

      mrjjM 1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #2

        https://doc.qt.io/qt-5/qmediaplayer.html#duration-prop
        duration is unavailable before a video starts. You can start to play it and stop it right after durationChange() signal is out. That is what I do in my code in order to display the duration in advance. There may be a query for this with gstreamer. I tried a few things, but they did not work out.

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

          i know i can get duration (and dimensions) if i play the video and wait for the signals. that's not my question.

          my question is can i do this all on a background thread?

          JoeCFDJ 1 Reply Last reply
          0
          • D davecotter

            i know i can get duration (and dimensions) if i play the video and wait for the signals. that's not my question.

            my question is can i do this all on a background thread?

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #4

            @davecotter It is pretty fast. Why do you need to play it in a thread? It would be perfect if duration can be queried with gstreamer without playing it.

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

              i'm not playing it, i'm gathering meta data.

              after my app imports a thousand songs, i need to gather the meta data for each song so it can eventually be displayed. there's no reason to take ANY cpu time away from the main thread for this, unless it's impossible to do on a back thread.

              please can someone just answer my question: can this be done on a back thread, yes or no?

              mrjjM 1 Reply Last reply
              0
              • D davecotter

                i'm not playing it, i'm gathering meta data.

                after my app imports a thousand songs, i need to gather the meta data for each song so it can eventually be displayed. there's no reason to take ANY cpu time away from the main thread for this, unless it's impossible to do on a back thread.

                please can someone just answer my question: can this be done on a back thread, yes or no?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #6

                @davecotter

                For video. No
                For Mp3. Yes (on windows at least)

                Mp3 could play and I could get Duration.

                For AVi file, it would say
                DirectShowPlayerService::doRender: Unknown error 0x80040266.

                Same avi file would play in the MediaPlayer example with no issues.

                Tested on Windows. Might be possible on linux/Mac as it is another backend.

                1 Reply Last reply
                2
                • D Offline
                  D Offline
                  davecotter
                  wrote on last edited by davecotter
                  #7

                  so the answer is "no you can't do it on a background thread. it must be done on the main UI thread"

                  mrjjM 1 Reply Last reply
                  0
                  • D davecotter

                    so the answer is "no you can't do it on a background thread. it must be done on the main UI thread"

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #8

                    @davecotter

                    Yes to No for video.

                    But you said
                    " imports a thousand songs"
                    and it does work for mp3 but
                    if those songs are videos then no.

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

                      the original question was:

                      get the dimensions and duration of a video

                      so, that's a "no, you can't". right? just want to double-confirm.

                      mrjjM 1 Reply Last reply
                      0
                      • D davecotter

                        the original question was:

                        get the dimensions and duration of a video

                        so, that's a "no, you can't". right? just want to double-confirm.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @davecotter

                        Assuming "after my app imports a thousand songs" talks about videos and hence we would have
                        no benefit from processing sound files then yes to " no, you cant"

                        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