QMediaPlayer - setPosition() problem
-
I want to set start position in "QMediaPlayer" object using setPosition() function, but unfortunately it doesn't work. Does anyone have an idea how to set the starting point correctly?
Thank you.Zbigniew
-
@Zbigniew-Sch said in QMediaPlayer - setPosition() problem:
if(status==QMediaPlayer::MediaStatus::BufferedMedia)
{
mediaPlayer->setPosition(m_iVideoPosition);
}Works like a charm, you are my hero today! :D
-
Hi,
When/How are you doing that ?
Which version of Qt ?
On which OS ? -
I want to start a video (mp4) from position "x" not from "0".
I have Qt version 6.4 on Windows 10 -
@Zbigniew-Sch Do you set the position before or right after you call
play()
?
You need wait the player to load and buffer the media.
connect themediaStatusChanged
signal and set the postion when the status isQMediaPlayer::BufferedMedia
. -
Thank you, it works fine.
But I have the next problem, I want to start the video, then position it at position "x" and pause.
Where can I call the "pause()" function and set the position "x"?
I made several attempts, but the position (mostly is 0) is wrong or the "QVideoWidget" content is black -
@Zbigniew-Sch Not sure what's your case, mine works when putting
pause()
right before or right aftersetPosition()
.
But it may depends on the media service plugin behaviour, for example when using windowsmediafoundation plugin under Windows, I just can't make the media pause. -
Hi Guys! I have a similar problem with my code:
QVideoWidget *vwidget = new QVideoWidget; QAudioOutput *audioOutput = new QAudioOutput; QMediaPlayer *mediaPlayer = new QMediaPlayer; mediaPlayer->setVideoOutput(vwidget ); mediaPlayer->setAudioOutput(audioOutput); mediaPlayer->setSource(QUrl::fromLocalFile("myvideo.mp4")); audioOutput->setVolume(0.002); mediaPlayer->play(); connect(mediaPlayer,&QMediaPlayer::mediaStatusChanged,this,[=](QMediaPlayer::MediaStatus status){ if(status==QMediaPlayer::MediaStatus::BufferedMedia) { mediaPlayer->pause(); mediaPlayer->setPosition(200000); mediaPlayer->pause(); } }); vwidget ->show();
its jump to the correct position of the video BUT the video didn't pause going on from the position... but why?:(
-
This post is deleted!
-
In the header file:
int m_iVideoPosition;
//======================================
mediaPlayer->setVideoOutput(vwidget); mediaPlayer->setAudioOutput(audioOutput); mediaPlayer->setSource(QUrl::fromLocalFile("myvideo.mp4")); audioOutput->setVolume(0.002); mediaPlayer->play(); m_iVideoPosition = 200000; connect(mediaPlayer, &QMediaPlayer::positionChanged, this, &QMyMediaPlayer::positionChanged); connect(mediaPlayer,&QMediaPlayer::mediaStatusChanged,this,[=](QMediaPlayer::MediaStatus status) { if(status==QMediaPlayer::MediaStatus::BufferedMedia) { mediaPlayer->setPosition(m_iVideoPosition); } }
//=======================================
void QMyMediaPlayer::positionChanged(qint64 position) { if (m_iVideoPosition != 0 && position > m_iVideoPosition) { m_iVideoPosition = 0; pause(); } }
-
@Zbigniew-Sch said in QMediaPlayer - setPosition() problem:
if(status==QMediaPlayer::MediaStatus::BufferedMedia)
{
mediaPlayer->setPosition(m_iVideoPosition);
}Works like a charm, you are my hero today! :D
-