When you load a file into a QMediaPlayer
instance, it does not automatically buffer the file. The MediaStatus
remains NoMedia
until you play the file using play()
, only after which it will end up as BufferedMedia
. I can't find any way in the documentation to force the player to buffer the file without playing it - is there any way to do this?
Right now I'm planning on muting it, playing the file, then stopping it again and unmuting it, but it makes me feel dirty. Surely there is a better way to do this?
This is necessary, by the way, because I can't retrieve the duration
until the file has been buffered, and I need the duration
to select a position
in the track to start playing from.
Thanks
Not in Qt 5, and its not the reason you can't know 'duration' and set 'position'. When you set the media with
setMedia
it does not wait for the media to finish loading (and does not check for errors). a signalmediaStatusChanged()
is emitted when media is loaded, so listen to that signal anderror()
signal to be notified when the media loading is finished.Once the media file is loaded and before play, you can check the duration and you can set the player to your desired position, but this is best to do once the duration changes from 0 to the media duration after loading, so connect to signal
durationChanged()
:Yes, create a buffer from file then set media content to your buffer (but this is not required to do the above, it just provides a faster way to seek in media):