diff options
Diffstat (limited to 'src/multimedia/audio/qsoundeffectwithplayer.cpp')
| -rw-r--r-- | src/multimedia/audio/qsoundeffectwithplayer.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/multimedia/audio/qsoundeffectwithplayer.cpp b/src/multimedia/audio/qsoundeffectwithplayer.cpp index 1a9ec7a4a..566977f08 100644 --- a/src/multimedia/audio/qsoundeffectwithplayer.cpp +++ b/src/multimedia/audio/qsoundeffectwithplayer.cpp @@ -152,7 +152,7 @@ void QSoundEffectPrivateWithPlayer::setResolvedAudioDevice(QAudioDevice device) }; m_voices.clear(); - bool hasPlayer = updatePlayer(); + bool hasPlayer = updatePlayer(m_sample); if (!hasPlayer) return; @@ -180,6 +180,7 @@ bool QSoundEffectPrivateWithPlayer::setSource(const QUrl &url, QSampleCache &sam m_url = url; m_sample = {}; + m_player = {}; if (url.isEmpty()) { setStatus(QSoundEffect::Null); @@ -202,12 +203,18 @@ bool QSoundEffectPrivateWithPlayer::setSource(const QUrl &url, QSampleCache &sam return; } + bool hasPlayer = updatePlayer(result); + if (!hasPlayer) { + qWarning("QSoundEffect: playback of this format is not supported on the selected " + "audio device"); + setStatus(QSoundEffect::Error); + return; + } + m_sample = std::move(result); setStatus(QSoundEffect::Ready); - bool hasPlayer = updatePlayer(); if (std::exchange(m_playPending, false)) { - if (hasPlayer) - play(); + play(); } } else { qWarning("QSoundEffect: Error decoding source %ls", qUtf16Printable(m_url.toString())); @@ -363,8 +370,9 @@ void QSoundEffectPrivateWithPlayer::play(std::shared_ptr<QSoundEffectVoice> voic emit q_ptr->playingChanged(); } -bool QSoundEffectPrivateWithPlayer::updatePlayer() +bool QSoundEffectPrivateWithPlayer::updatePlayer(const SharedSamplePtr &sample) { + Q_ASSERT(sample); Q_ASSERT(m_voices.empty()); QObject::disconnect(m_voiceFinishedConnection); @@ -372,8 +380,10 @@ bool QSoundEffectPrivateWithPlayer::updatePlayer() if (m_resolvedAudioDevice.isNull()) return false; - auto player = QRtAudioEngine::getEngineFor(m_resolvedAudioDevice, m_sample->format()); + auto player = QRtAudioEngine::getEngineFor(m_resolvedAudioDevice, sample->format()); m_player = player; + if (!m_player) + return false; m_voiceFinishedConnection = QObject::connect(m_player.get(), &QRtAudioEngine::voiceFinished, this, [this](VoiceId voiceId) { |
