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?!
-
I'm not sure... but I think you're using the wrong signal.
bufferStatus is correct when you use phonon in BufferingStateI think you shall use tick() signal.
-
QObject::connect: Incompatible sender/receiver arguments
Phonon::MediaObject::tick(qint64) --> QProgressBar::setValue(int):(
-
I did some tests, but neither tick(qint64) or bufferStatus(int) never gets emitted. Is it a bug? Am I initializing it wrong?
-
You're missing something.
I've just compiled Phonon demo and progres bar works fine (on Qt 4.8)
I didn't see any special configuration to mediaObject to emit this signal.
Take care using the same var type (int64 in your slot)Take a look to Phonon example.
-
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);
}@ -
Yay, thank you! It works now!
Btw, why setTickInterval(200) ? -
200 ms. is an arbitrary interval :P
If you want more precision, reduce it. -
Thank you! You helped me a lot!