diff --git a/src/modules/snd/libkvisnd.cpp b/src/modules/snd/libkvisnd.cpp index 410c146a0..506664d88 100644 --- a/src/modules/snd/libkvisnd.cpp +++ b/src/modules/snd/libkvisnd.cpp @@ -35,7 +35,10 @@ #include "KviQString.h" #ifdef COMPILE_QTMULTIMEDIA_SUPPORT -#include +#include +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include +#endif #endif //!COMPILE_QTMULTIMEDIA_SUPPORT #ifdef COMPILE_PHONON_SUPPORT @@ -89,7 +92,10 @@ KviSoundPlayer::KviSoundPlayer() #endif //!COMPILE_PHONON_SUPPORT #ifdef COMPILE_QTMULTIMEDIA_SUPPORT - m_pSoundEffect = nullptr; + m_pMediaPlayer = nullptr; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + m_pAudioOutput = nullptr; +#endif #endif //COMPILE_QTMULTIMEDIA_SUPPORT m_pLastUsedSoundPlayerEntry = nullptr; @@ -138,8 +144,12 @@ KviSoundPlayer::~KviSoundPlayer() #endif //COMPILE_PHONON_SUPPORT #ifdef COMPILE_QTMULTIMEDIA_SUPPORT - if(m_pSoundEffect) - delete m_pSoundEffect; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + if(m_pAudioOutput) + delete m_pAudioOutput; +#endif + if(m_pMediaPlayer) + delete m_pMediaPlayer; #endif //!COMPILE_QTMULTIMEDIA_SUPPORT g_pSoundPlayer = nullptr; @@ -182,6 +192,13 @@ bool KviSoundPlayer::havePlayingSounds() if(m_pThreadList) if(m_pThreadList->count() > 0) return true; + +#ifdef COMPILE_QTMULTIMEDIA_SUPPORT + if(m_pMediaPlayer) + if(m_pMediaPlayer->isPlaying()) + return true; +#endif + #ifdef COMPILE_PHONON_SUPPORT if(m_pPhononPlayer) if(m_pPhononPlayer->state() == Phonon::PlayingState) @@ -219,14 +236,14 @@ bool KviSoundPlayer::detectSoundSystem(QString & szSoundSystem) szSoundSystem = "winmm"; return true; #endif -#ifdef COMPILE_PHONON_SUPPORT - szSoundSystem = "phonon"; - return true; -#endif //!COMPILE_PHONON_SUPPORT #ifdef COMPILE_QTMULTIMEDIA_SUPPORT szSoundSystem = "qt"; return true; #endif +#ifdef COMPILE_PHONON_SUPPORT + szSoundSystem = "phonon"; + return true; +#endif //!COMPILE_PHONON_SUPPORT #ifdef COMPILE_OSS_SUPPORT #ifdef COMPILE_AUDIOFILE_SUPPORT szSoundSystem = "oss+audiofile"; @@ -336,21 +353,25 @@ bool KviSoundPlayer::playQt(const QString & szFileName) if(isMuted()) return true; - if(!m_pSoundEffect) - m_pSoundEffect = new QSoundEffect; - m_pSoundEffect->setSource(QUrl::fromLocalFile(szFileName)); - m_pSoundEffect->play(); + if(!m_pMediaPlayer) + m_pMediaPlayer = new QMediaPlayer; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + m_pAudioOutput = new QAudioOutput; + m_pMediaPlayer->setAudioOutput(m_pAudioOutput); +#endif + m_pMediaPlayer->setSource(QUrl::fromLocalFile(szFileName)); + m_pMediaPlayer->play(); return true; } void KviSoundPlayer::cleanupQt() { - if(!m_pSoundEffect) + if(!m_pMediaPlayer) return; - m_pSoundEffect->stop(); - delete m_pSoundEffect; - m_pSoundEffect = nullptr; + m_pMediaPlayer->stop(); + delete m_pMediaPlayer; + m_pMediaPlayer = nullptr; } #endif diff --git a/src/modules/snd/libkvisnd.h b/src/modules/snd/libkvisnd.h index 18a3ef4e4..2ebcbdbdc 100644 --- a/src/modules/snd/libkvisnd.h +++ b/src/modules/snd/libkvisnd.h @@ -88,7 +88,10 @@ namespace Phonon #endif //!COMPILE_PHONON_SUPPORT #ifdef COMPILE_QTMULTIMEDIA_SUPPORT - class QSoundEffect; + class QMediaPlayer; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + class QAudioOutput; +#endif #endif typedef bool (KviSoundPlayer::*SoundSystemPlayRoutine)(const QString & szFileName); @@ -146,7 +149,10 @@ class KviSoundPlayer : public QObject Phonon::MediaObject * m_pPhononPlayer; #endif //!COMPILE_PHONON_SUPPORT #ifdef COMPILE_QTMULTIMEDIA_SUPPORT - QSoundEffect * m_pSoundEffect; + QMediaPlayer * m_pMediaPlayer; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QAudioOutput * m_pAudioOutput; +#endif #endif //!COMPILE_QTMULTIMEDIA_SUPPORT KviSoundPlayerEntry * m_pLastUsedSoundPlayerEntry;