QMediaPlayer on background thread?
-
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?
-
so the answer is "no you can't do it on a background thread. it must be done on the main UI thread"
-
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. -
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?
-
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?
@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.
-
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?
-
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?
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.
-
so the answer is "no you can't do it on a background thread. it must be done on the main UI thread"
-
so the answer is "no you can't do it on a background thread. it must be done on the main UI thread"
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. -
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.
-
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.
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"