Media player not working for multiple videos
-
Declare
QPushButton
as a local variable like amediaPlayer
. A lambda function can not capture member variables ofthis
.@Devopia53 No, it can:
auto l = [this]() { // use members of this here }
-
I still have a question . I replaced the slider slots into loop but I can't control the sliders and sliders are not moving when the videos are running .
Here is the slider codeQSlider *m_positionSlider = new QSlider(Qt::Horizontal); m_positionSlider->setRange(0, 0); connect(mediaPlayer, &QMediaPlayer::positionChanged ,[m_positionSlider, this](qint64 position){ m_positionSlider->setValue(position); }); connect(mediaPlayer, &QMediaPlayer::durationChanged ,[m_positionSlider, this](qint64 duration){ m_positionSlider->setRange(0,duration); }); connect(mediaPlayer , &QMediaPlayer::setPosition, [mediaPlayer ,this] (int position){ mediaPlayer->setPosition(position); });
-
I still have a question . I replaced the slider slots into loop but I can't control the sliders and sliders are not moving when the videos are running .
Here is the slider codeQSlider *m_positionSlider = new QSlider(Qt::Horizontal); m_positionSlider->setRange(0, 0); connect(mediaPlayer, &QMediaPlayer::positionChanged ,[m_positionSlider, this](qint64 position){ m_positionSlider->setValue(position); }); connect(mediaPlayer, &QMediaPlayer::durationChanged ,[m_positionSlider, this](qint64 duration){ m_positionSlider->setRange(0,duration); }); connect(mediaPlayer , &QMediaPlayer::setPosition, [mediaPlayer ,this] (int position){ mediaPlayer->setPosition(position); });
@Kinesis What is this:
connect(mediaPlayer , &QMediaPlayer::setPosition, [mediaPlayer ,this] (int position){ mediaPlayer->setPosition(position); });
?
QMediaPlayer::setPosition() is a slot not a signal.
I think you need to change the rangem_positionSlider->setRange(0, 0);
You can use http://doc.qt.io/qt-5/qmediaplayer.html#duration-prop to set the range.
-
@Devopia53 No, it can:
auto l = [this]() { // use members of this here }
I know that well(as
[&]
or[=]
). But what I have described is that you have captured the member variables of thethis
object directly. Take a look at his source code. here:connect(mediaPlayer, &QMediaPlayer::stateChanged, [m_playButton, this](QMediaPlayer::State state)
Am_playButton
is a member of thethis
. -
@Kinesis What is this:
connect(mediaPlayer , &QMediaPlayer::setPosition, [mediaPlayer ,this] (int position){ mediaPlayer->setPosition(position); });
?
QMediaPlayer::setPosition() is a slot not a signal.
I think you need to change the rangem_positionSlider->setRange(0, 0);
You can use http://doc.qt.io/qt-5/qmediaplayer.html#duration-prop to set the range.
-
@jsulm
Thanks for your suggestion . Now the slider is running along with video.But to use it like skip slider how should I correct this "QMediaPlayer::setPosition() " which is a slot but not a signal ?By the way , sorry for late response . -
@Kinesis You don't need
connect(mediaPlayer , &QMediaPlayer::setPosition, [mediaPlayer ,this] (int position){ mediaPlayer->setPosition(position); });
You're already using QMediaPlayer::positionChanged...
-
@jsulm
I got this. It's done now. My code is working fully 100% now . Thanks a lot for helping me . I fell bad that I wasted your time . By the way should I upload my
code ? It might help someone . Thanks. -
This post is deleted!