PDA

View Full Version : Connecting QMediaPlayer object to horizontal slider?



antweb
19th March 2015, 17:12
How can I do this? Since phonon has been removed for version 5 and above, how do I show the status of my mediaplayer on a horizontal slider?
I tried doing this:


ui->hs->setRange(0, player.duration() / 1000);
ui->hs->setEnabled(player.duration() > 0);
connect(ui->hs, SIGNAL(valueChanged(int)), this, SLOT(seek(int)));


void MainWindow::seek(int seconds)
{
player.setPosition(seconds * 1000);
}


This does not even activate my horizontal slider. What is the issue?

obiwankennedy
23rd March 2015, 12:03
Example here :
https://github.com/obiwankennedy/rolisteam/blob/master/src/audio/playerwidget.cpp


connect(&m_player,SIGNAL(positionChanged(qint64)),this,SLOT (positionChanged(qint64)));


and


void PlayerWidget::positionChanged(qint64 time)
{
QTime displayTime(0, (time / 60000) % 60, (time / 1000) % 60);
if((!m_preferences->value("isPlayer",false).toBool()) && ((time>m_time+(FACTOR_WAIT*m_player.notifyInterval()))||( time<m_time)))
{
emit playerPositionChanged(m_id,time);
}
m_time = time;
m_ui->m_timeSlider->setValue(time);
m_ui->m_timerDisplay->display(displayTime.toString("mm:ss"));
}

In fact, there is an issue about the type. You have to put a slot in the middle.