QMediaPlayer:发出 positionChanged() 时声音中断
QMediaPlayer: Sound interrupts when positionChanged() is emitted
我和QMediaPlayer positionChanged(). Sound inteerupts on slider updating
有同样的问题
我使用 QMediayPlayer,每次发出信号 positionChanged() 以更新我的滑块位置并为滑块设置新值时,声音会中断片刻。
这是在构造函数中:
soundfile = new QMediaPlayer(this, QMediaPlayer::LowLatency); //soundfile is a pointer of a QMediaPlayer Object
QObject::connect(soundfile, SIGNAL(positionChanged(qint64)), this, SLOT(changedPosition(qint64)));
这是槽函数:
void Soundfile::changedPosition(qint64 p) {
QTime time(0,0,0,0);
time = time.addMSecs(soundfile->position());
if(p != 0) recordSlider->setValue(p); //THIS IS THE LINE, WHERE IT INTERRUPTS
changeRecordTime(QString::number(p));
recordPositionLabel->setText("Aktuelle Zeit: " + time.toString());
}
recordSlider 是一个 QSlider。
如果我用 setValue 注释掉这一行,一切正常。
有人知道吗?
我认为问题是:当媒体播放器发出 SIGNAL
时,会调用 SLOT
,而当您在函数中使用 setValue
时,setValue
再次发出 SIGNAL
,该过程再次发生。
为了解决这个问题,我禁用了滑块跟踪并使用 setSliderPosition
移动位置。
示例:
slider->setTracking(false);
slider->setSliderPosition(pos);
我和QMediaPlayer positionChanged(). Sound inteerupts on slider updating
有同样的问题我使用 QMediayPlayer,每次发出信号 positionChanged() 以更新我的滑块位置并为滑块设置新值时,声音会中断片刻。
这是在构造函数中:
soundfile = new QMediaPlayer(this, QMediaPlayer::LowLatency); //soundfile is a pointer of a QMediaPlayer Object
QObject::connect(soundfile, SIGNAL(positionChanged(qint64)), this, SLOT(changedPosition(qint64)));
这是槽函数:
void Soundfile::changedPosition(qint64 p) {
QTime time(0,0,0,0);
time = time.addMSecs(soundfile->position());
if(p != 0) recordSlider->setValue(p); //THIS IS THE LINE, WHERE IT INTERRUPTS
changeRecordTime(QString::number(p));
recordPositionLabel->setText("Aktuelle Zeit: " + time.toString());
}
recordSlider 是一个 QSlider。 如果我用 setValue 注释掉这一行,一切正常。
有人知道吗?
我认为问题是:当媒体播放器发出 SIGNAL
时,会调用 SLOT
,而当您在函数中使用 setValue
时,setValue
再次发出 SIGNAL
,该过程再次发生。
为了解决这个问题,我禁用了滑块跟踪并使用 setSliderPosition
移动位置。
示例:
slider->setTracking(false);
slider->setSliderPosition(pos);