PDA

View Full Version : QMediaPlayer: positionChanged() Signal interrupts sound



ChristianH
18th March 2015, 13:00
Hello,

i am programming a software which includes playing a sound file.

Everytime when the signal positionChanged(qint64) is emitted, my position slider should update the current position of the sound file. This works fine, but everytime when this happens (every second) the sound interrupts for a moment.

In my class Soundfile i create a pointer of QMediaPlayer named soundfile.


QMediaPlayer* soundfile;

In the constructor Soundfile() i wrote this:


soundfile = new QMediaPlayer(this, QMediaPlayer::LowLatency);
QObject::connect(soundfile, SIGNAL(positionChanged(qint64)), this, SLOT(changedPosition(qint64)));

The slot changedPosition in the class Soundfile is this:

void Soundfile::changedPosition(qint64 p) {

QTime time(0,0,0,0);
time = time.addMSecs(soundfile->position());

if(p != 0) recordSlider->setValue(p);
changeRecordTime(QString::number(p));
recordPositionLabel->setText("Current time: " + time.toString());
}

(the rest is updating the current time label)

Is there any problem why it could interrupting playing the sound file?

I hope someone has an idea.

With best regards,
Christian

anda_skoa
19th March 2015, 08:00
Have you checked how long the slot needs to execute?
If it exceeds the time the player has buffered data for, then it can't play any further until the slot returns.

Cheers,
_