QMediaPlayer:发出positionChanged()时声音中断
QMediaPlayer: Sound interrupts when positionChanged() is emitted
我也有类似QMediaPlayer positionChanged()的问题。滑块更新时声音爆发
我使用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);
相关文章:
- Xaudio2在更改缓冲区或循环时弹出声音
- 如何更改'a'声音?
- 类成员和中断
- 如何收听Windows当前正在播放的声音?
- 捕获标准输出以压缩并使用 CTRL-C 中断会给出损坏的 zip 文件
- 我的代码运行良好,但在游戏循环中中断
- 使用带有MCP23017的 pigpio 进行中断读取
- 为什么我在 AVR 中的中断无法正常工作?
- 使用 UDP 中断 while()-循环
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何在 CompleteAsyncIO 中访问 IOMemoryBufferDescriptor,该描述符通过中断 EP
- 如何为伺服电机创建中断或返回值?
- 开关:无外壳中断
- 如何在 c++ 中循环中使用频率变化的声音?
- 如何使用中断停止循环?
- 为什么当我输入一个被接受的数字时,我的 do-while 循环没有中断?
- 在 Ubuntu 中编译 SuiteSparse,在安装 CHOLMOD 时中断
- 在PROGMEM中添加更多数据会中断Arduino Mega 2560上的SPI传输
- 使用 std::weak_ptr 和别名构造函数中断循环引用:声音或有问题
- QMediaPlayer:发出positionChanged()时声音中断