Seek in sound file: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
(No difference)

Revision as of 17:42, 14 January 2015

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: