Seek in Sound File

From Qt Wiki
Revision as of 17:42, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

Categories: