From 1124d6b073546bacd58bce640bbcc08db4f8b341 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 20:39:08 +0200 Subject: [PATCH] `QMediaPlayer` instead of `QSoundEffect` for SFX and blips. Maybe temporary. --- aoblipplayer.cpp | 7 ++++--- aoblipplayer.h | 4 ++-- aosfxplayer.cpp | 6 +++--- aosfxplayer.h | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index 5e3929e..c58e2cc 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -2,9 +2,9 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { - m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; + m_sfxplayer = new QMediaPlayer(m_parent, QMediaPlayer::Flag::LowLatency); } AOBlipPlayer::~AOBlipPlayer() @@ -17,17 +17,18 @@ void AOBlipPlayer::set_blips(QString p_sfx) { m_sfxplayer->stop(); QString f_path = ao_app->get_sounds_path() + p_sfx.toLower(); - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); set_volume(m_volume); } void AOBlipPlayer::blip_tick() { + //m_sfxplayer->stop(); m_sfxplayer->play(); } void AOBlipPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + m_sfxplayer->setVolume(p_value); } diff --git a/aoblipplayer.h b/aoblipplayer.h index c8a8cb6..b460196 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class AOBlipPlayer { @@ -23,7 +23,7 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; + QMediaPlayer *m_sfxplayer; int m_volume; }; diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 972cd74..9089aec 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -4,7 +4,7 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - m_sfxplayer = new QSoundEffect(); + m_sfxplayer = new QMediaPlayer(m_parent, QMediaPlayer::Flag::LowLatency); } AOSfxPlayer::~AOSfxPlayer() @@ -26,7 +26,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) else f_path = ao_app->get_sounds_path() + p_sfx; - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); set_volume(m_volume); m_sfxplayer->play(); @@ -40,5 +40,5 @@ void AOSfxPlayer::stop() void AOSfxPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + m_sfxplayer->setVolume(p_value); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 1b73e49..ab9fd97 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class AOSfxPlayer { @@ -21,7 +21,7 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; + QMediaPlayer *m_sfxplayer; int m_volume = 0; };