mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
new simple solution for sound on linux based on using system sound player. To be tested.
This commit is contained in:
parent
9999742ec7
commit
9347b86e63
@ -20,6 +20,8 @@
|
||||
****************************************************************/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QProcess>
|
||||
#include <QSound>
|
||||
#include <QDir>
|
||||
|
||||
@ -28,6 +30,10 @@
|
||||
#include <QAudioDeviceInfo>
|
||||
#endif
|
||||
|
||||
// #ifdef QMEDIAPLAYER
|
||||
// #nclude <QMediaPlayer>
|
||||
// #endif
|
||||
|
||||
#include "SoundManager.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include "retroshare/rsinit.h"
|
||||
@ -234,12 +240,60 @@ void SoundManager::playFile(const QString &filename)
|
||||
}
|
||||
|
||||
QString playFilename = realFilename(filename);
|
||||
bool played = false ;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK (5, 0, 0)
|
||||
if (!QAudioDeviceInfo::availableDevices(QAudio::AudioOutput).isEmpty())
|
||||
#else
|
||||
if (QSound::isAvailable())
|
||||
#endif
|
||||
{
|
||||
QSound::play(playFilename);
|
||||
played = true ;
|
||||
}
|
||||
|
||||
if(!played) // let's go for the hard core stuff
|
||||
{
|
||||
// #ifdef QMEDIAPLAYER
|
||||
// static QMediaPlayer *qmplayer;
|
||||
// if (qmplayer == NULL) {
|
||||
// qmplayer = new QMediaPlayer();
|
||||
// qmplayer->setMedia(QMediaContent(QUrl::fromLocalFile(playFilename)));
|
||||
// }
|
||||
// std::cerr << "Play QMediaPlayer" << std::endl;
|
||||
// qmplayer->play();
|
||||
// return;
|
||||
// #endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
QString player_cmd = soundDetectPlayer();
|
||||
QStringList args = player_cmd.split(' ');
|
||||
args += filename;
|
||||
QString prog = args.takeFirst();
|
||||
//std::cerr << "Play " << prog.toStdString() << std::endl;
|
||||
QProcess::startDetached(prog, args);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
/** Detect default player helper on unix like systems
|
||||
* Inspired by Psi IM (0.15) in common.cpp
|
||||
*/
|
||||
QString SoundManager::soundDetectPlayer()
|
||||
{
|
||||
// prefer ALSA on linux
|
||||
|
||||
if (QFile("/proc/asound").exists()) {
|
||||
return "aplay -q";
|
||||
}
|
||||
// fallback to "play"
|
||||
return "play";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -67,6 +67,10 @@ signals:
|
||||
public:
|
||||
static void create();
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
static QString soundDetectPlayer();
|
||||
#endif
|
||||
|
||||
static void initDefault();
|
||||
static QString defaultFilename(const QString &event, bool check);
|
||||
static QString convertFilename(const QString &filename);
|
||||
|
Loading…
Reference in New Issue
Block a user