Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Seek in Sound File
Jump to navigation
Jump to search
How to Seek in Sound File
I tried to play a sound file not at the beginning but with an offset of 20 seconds.
The following way of setting an offset fails:
It does not work because QMediaPlayer works asynchronously.
As soon as the seek operations are delayed everything works as intended. For example:
To make my life easier I have derived a class MediaPlayer from QMediaPlayer and added a blocking load method:
When files are loaded with this blocking load method
setPosition()
can be called right in the next source line.
loadBlocking
blocks until signal
seekableChanged()
is emitted. To avoid a deadlock, maximum waiting time is 2 seconds.