Skip to content

Commit

Permalink
app: qt 6 audio fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramen2X committed Jan 20, 2024
1 parent 68c35f3 commit 9b3a8da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions app/viewer/mediapanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ void MediaPanel::Play(bool e)
auto output_dev = QAudioDevice(QMediaDevices::defaultAudioOutput());
auto fmt = output_dev.preferredFormat();

ClearAudioSinks();

for (auto it=m_mediaInstances.cbegin(); it!=m_mediaInstances.cend(); it++) {
auto m = *it;

Expand All @@ -407,7 +409,6 @@ void MediaPanel::Play(bool e)
auto out = new QAudioSink(output_dev, fmt, this);
out->setVolume(m->GetVolume());
out->start(m);
connect(out, &QAudioSink::stateChanged, this, &MediaPanel::AudioStateChanged);
m_audioSinks.push_back(out);
has_audio = true;
}
Expand Down Expand Up @@ -449,9 +450,7 @@ void MediaPanel::TimerUpdate()
}

if (all_eof) {
// Detach audio output so that it flushes itself
m_audioSinks.clear();

ClearAudioSinks();
Play(false);
m_PlayheadSlider->setValue(m_PlayheadSlider->maximum());
}
Expand Down Expand Up @@ -506,17 +505,13 @@ void MediaPanel::LabelContextMenuTriggered(const QPoint &pos)
m.exec(static_cast<QWidget*>(sender())->mapToGlobal(pos));
}

void MediaPanel::AudioStateChanged(QAudio::State newState)
void MediaPanel::ClearAudioSinks()
{
if (newState == QAudio::IdleState) {
auto out = static_cast<QAudioSink*>(sender());
if (m_audioSinks.size() != 0) {
for (auto s : m_audioSinks)
delete s;

auto it = std::find(m_audioSinks.begin(), m_audioSinks.end(), out);
if (it != m_audioSinks.end()) {
m_audioSinks.erase(it);
}

delete out;
m_audioSinks.clear();
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/viewer/mediapanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private slots:

void LabelContextMenuTriggered(const QPoint &pos);

void AudioStateChanged(QAudio::State newState);
void ClearAudioSinks();

};

Expand Down

0 comments on commit 9b3a8da

Please sign in to comment.