I'm not sure what your play / pause buttons do, but I am building a Phonon application for streaming audio, and I could not find a good way to get the current state of the media object.
The closest I can get is to create a slot and connect it to the signal stateChanged()that it emits MediaObject. I ended up with this:
MyMediaPlayer::MyMediaPlayer(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MyMediaPlayer)
{
...
connect(mediaObj, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this, SLOT(handleMediaState(Phonon::State,Phonon::State)));
}
...
void MyMediaPlayer::handleMediaState(Phonon::State state, Phonon::State)
{
switch (state)
{
case Phonon::PlayingState:
case Phonon::LoadingState:
case Phonon::BufferingState:
ui->playPauseButton->setIcon(QIcon(":/assets/stock_media-pause.svg"));
connect(ui->playPauseButton, SIGNAL(clicked()),
mediaObj, SLOT(pause()));
break;
case Phonon::PausedState:
case Phonon::StoppedState:
ui->playPauseButton->setIcon(QIcon(":/assets/stock_media-play.svg"));
connect(ui->playPauseButton, SIGNAL(clicked()),
mediaObj, SLOT(play()));
case Phonon::ErrorState:
break;
default:
break;
}
}
I'm not a fan of connecting and reconnecting, but I think this is Qt's way of doing this.
source
share