Seeking with QMediaPlayer
-
This is not a question but a solution. I tried to play a sound file not at the beginning but with an offset of 20 seconds.
The following fails:
@player = new QMediaPlayer(this);
player->setMedia(QUrl::fromLocalFile("myCoolSong.mp3"));
player->setVolume(50);
player->play(); // music can be heard
qDebug() << player->isSeekable(); // is always false
player->setPosition ( 20*1000 ); //does not work@It does not work because QMediaPlayer works asynchronously.
As soon as the seek operations are delayed everything works as intended. For example:@CoolPlayer::on_Button1_clicked()
{
qDebug() << player->isSeekable(); // true
player->setPosition ( 20*1000 );
}@This should be mentioned in the documentation. For Qt we have the "fantastic new online version":http://developer.qt.nokia.com/doc/qt-4.7/ where annotations can be posted. Unfortunately Mobility is not yet integrated.
-
On popular request here is the article in the wiki. As a bonus it comes with a blocking setMedia() method.
http://developer.qt.nokia.com/wiki/seek_in_sound_file