looping problem in phonon audio player-in Qt
A song is set as static in Phonon audio player. The loop works using aboutToFinish()
. The problem开发者_运维技巧 is that there is a 1 sec delay at the end of the song, then the song repeats.
How can we avoid the delay? I have also stored in a temporary buffer (using QBuffer
), for playing it. But it is not giving solution for looping issue.
musicpath="sound/sample.mp3";
Phonon::AudioOutput *audioOutput;
Phonon::VolumeSlider *volumeSlider;
Phonon::MediaObject *mediaObject;
mediaObject = new Phonon::MediaObject(this);
mediaObject->setCurrentSource(Phonon::MediaSource( musicpath));
connect(mediaObject, SIGNAL(aboutToFinish()),mediaObject,SLOT(stop()));
connect(mediaObject, SIGNAL(aboutToFinish()),mediaObject,SLOT(play()));
Phonon::createPath(mediaObject, audioOutput);
volumeSlider->setAudioOutput(audioOutput);
mediaObject->play();
I think best choice is checking for state of video is by using timer with 1 ms and play it if end
timer = new QTimer;
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timer_overflow()));
timer->start(1);
void MainWindow::timer_overflow()
{
if(ui->videoPlayer->isPaused())
{
video=Phonon::createPlayer(Phonon::VideoCategory,Phonon::MediaSource("video/back);
ui->videoPlayer->load(Phonon::MediaSource("video/background_video.wmv"));
ui->videoPlayer->play();
}
}
精彩评论