Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.



  • You could always make this into a little wiki article here on QtDevNet until such time as the mobility stuff is added to the docs here. Then you could add a docnote that links to the wiki article.



  • 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



  • could any one explain me this thing coz i also want o seek a video and i didnt get it how it works in the 2nd code which is written above
    Plz help


Log in to reply