+ qreal volume = settings.value("volume", 1.).toReal();
+ media->setVolume(volume);
+
+ connect(media, &Media::error, this, &MainWindow::handleError);
+ connect(media, &Media::stateChanged, this, &MainWindow::stateChanged);
+ connect(media, &Media::positionChanged, this, &MainWindow::tick);
+
+ connect(seekSlider, &QSlider::sliderMoved, this, [this](int value) {
+ // value : maxValue = posit ion : duration
+ qint64 ms = (value * media->duration()) / seekSlider->maximum();
+ qDebug() << "Seeking to" << ms;
+ media->seek(ms);
+ if (media->state() == Media::PausedState) media->play();
+ });
+ connect(seekSlider, &QSlider::sliderPressed, this, [this]() {
+ // value : maxValue = position : duration
+ qint64 ms = (seekSlider->value() * media->duration()) / seekSlider->maximum();
+ media->seek(ms);
+ if (media->state() == Media::PausedState) media->play();
+ });
+ connect(media, &Media::started, this, [this]() { seekSlider->setValue(0); });
+
+ connect(media, &Media::volumeChanged, this, &MainWindow::volumeChanged);
+ connect(media, &Media::volumeMutedChanged, this, &MainWindow::volumeMutedChanged);
+ connect(volumeSlider, &QSlider::sliderMoved, this, [this](int value) {
+ qreal volume = (qreal)value / volumeSlider->maximum();
+ media->setVolume(volume);
+ });
+ connect(volumeSlider, &QSlider::sliderPressed, this, [this]() {
+ qreal volume = (qreal)volumeSlider->value() / volumeSlider->maximum();
+ media->setVolume(volume);
+ });
+
+ mediaView->setMedia(media);