Phonon and bufferStatus signal.
-
Hi, I'm having problem with Phonon and progress bar. I want to increase progress bar while music plays but bufferStatus signal fails I think. Here's code:
[code] Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("C:/Users/User/Desktop/test.mp3"));
ui->progressBar->setRange(0, 100);
ui->progressBar->setValue(0);
connect(music, SIGNAL(bufferStatus(int)), ui->progressBar, SLOT(setValue(int)));
music->play();[/code]Music plays well, but progress bar is always zero. What's problem?!
-
-
Hi, documentation says if you want to use player with progress bar, use bufferStatus signal. Neither works for me.. Look at this, it doesn't work. Can you post code that worked for you? Thank you.
[code]MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("C:/Users/User/Desktop/test.mp3"));
ui->progressBar->setRange(0, 100);
ui->progressBar->setValue(0);
connect(music, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
music->play();
}void MainWindow::tick(qint64 x)
{
ui->label->setText(QString::number(x)); //set label text, for test..
}[/code] -
Ok, I'd found it.
In demo code doesn't configure it, but it's necesary to configure tickInterval property as it is 0 by default.
Just include music.setTickInterval(1) and will work.
look:
@#include "MainWindow.h"
#include "ui_MainWindow.h"#include <phonon>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
pb = ui->progressBar;
pb->setFormat("%v/%m (%p%)");
Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("C:/Users/Public/Music/Sample Music/Kalimba.mp3"));
music->setTickInterval(200);
connect(music, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
connect(music, SIGNAL(totalTimeChanged(qint64)), this, SLOT(maxTime(qint64)));
music->play();
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::tick(qint64 x)
{
pb->setValue(x);
}void MainWindow::maxTime(qint64 x)
{
pb->setMaximum(x);
}@