mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-12-16 17:13:58 -05:00
Replaced deprecated QSound and QAudioDeviceInfo by QAudioDevice and QMediaDevices for Qt 6
This commit is contained in:
parent
15684bf8d3
commit
95127592d7
2 changed files with 32 additions and 4 deletions
|
|
@ -21,12 +21,22 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSound>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0)
|
||||||
|
#include <QAudioDevice>
|
||||||
|
#include <QMediaDevices>
|
||||||
|
#include <QUrl>
|
||||||
|
#elif QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
||||||
|
#include <QAudioDeviceInfo>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK (6, 0, 0)
|
||||||
|
#include <QSound>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
||||||
#include <QAudio>
|
#include <QAudio>
|
||||||
#include <QAudioDeviceInfo>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// #ifdef QMEDIAPLAYER
|
// #ifdef QMEDIAPLAYER
|
||||||
|
|
@ -242,14 +252,24 @@ void SoundManager::playFile(const QString &filename)
|
||||||
QString playFilename = realFilename(filename);
|
QString playFilename = realFilename(filename);
|
||||||
bool played = false ;
|
bool played = false ;
|
||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0)
|
||||||
|
if (!QMediaDevices::audioOutputs().isEmpty())
|
||||||
|
#elif QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
||||||
if (!QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).isEmpty())
|
if (!QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).isEmpty())
|
||||||
#else
|
#else
|
||||||
if (QSound::isAvailable())
|
if (QSound::isAvailable())
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0)
|
||||||
|
if (soundManager) {
|
||||||
|
soundManager->mSoundEffect.setSource(QUrl::fromLocalFile(playFilename));
|
||||||
|
soundManager->mSoundEffect.play();
|
||||||
|
played = true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
QSound::play(playFilename);
|
QSound::play(playFilename);
|
||||||
played = true ;
|
played = true ;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!played) // let's go for the hard core stuff
|
if(!played) // let's go for the hard core stuff
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0)
|
||||||
|
#include <QSoundEffect>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SOUND_NEW_CHAT_MESSAGE "NewChatMessage"
|
#define SOUND_NEW_CHAT_MESSAGE "NewChatMessage"
|
||||||
#define SOUND_USER_ONLINE "User_go_Online"
|
#define SOUND_USER_ONLINE "User_go_Online"
|
||||||
#define SOUND_MESSAGE_ARRIVED "MessageArrived"
|
#define SOUND_MESSAGE_ARRIVED "MessageArrived"
|
||||||
|
|
@ -91,6 +95,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SoundManager();
|
SoundManager();
|
||||||
|
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK (6, 0, 0)
|
||||||
|
QSoundEffect mSoundEffect;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern SoundManager *soundManager;
|
extern SoundManager *soundManager;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue