initial port for Cevo game in C++ (libs)
This commit is contained in:
commit
8436242032
375 files changed
+46282
No files matched your search
@@ -0,0 +1,75 @@
|
||||
#include "Uos/UosPlayer.h"
|
||||
|
||||
#include <QAudioDevice>
|
||||
#include <QAudioOutput>
|
||||
#include <QFileInfo>
|
||||
#include <QMediaDevices>
|
||||
#include <QUrl>
|
||||
|
||||
namespace Uos {
|
||||
|
||||
bool isAudioOutputAvailable()
|
||||
{
|
||||
return !QMediaDevices::defaultAudioOutput().isNull();
|
||||
}
|
||||
|
||||
Player::Player(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_player = new QMediaPlayer(this);
|
||||
m_audioOutput = new QAudioOutput(this);
|
||||
m_player->setAudioOutput(m_audioOutput);
|
||||
connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &Player::handleMediaStatusChanged);
|
||||
}
|
||||
|
||||
bool Player::addFromFile(const QString &fileName)
|
||||
{
|
||||
if (!QFileInfo::exists(fileName))
|
||||
return false;
|
||||
m_player->setSource(QUrl::fromLocalFile(fileName));
|
||||
return true;
|
||||
}
|
||||
|
||||
qint64 Player::inputLength() const
|
||||
{
|
||||
return m_player->duration();
|
||||
}
|
||||
|
||||
void Player::setVolume(float left, float right, bool smooth)
|
||||
{
|
||||
Q_UNUSED(smooth);
|
||||
m_audioOutput->setVolume((left + right) / 2.0f);
|
||||
}
|
||||
|
||||
float Player::volume() const
|
||||
{
|
||||
return m_audioOutput->volume();
|
||||
}
|
||||
|
||||
bool Player::addIntoDevOut()
|
||||
{
|
||||
return isAudioOutputAvailable();
|
||||
}
|
||||
|
||||
void Player::play(int loopCount)
|
||||
{
|
||||
m_player->setLoops(loopCount <= 1 ? 1 : loopCount);
|
||||
m_player->play();
|
||||
}
|
||||
|
||||
void Player::stop()
|
||||
{
|
||||
m_player->stop();
|
||||
}
|
||||
|
||||
bool Player::playing() const
|
||||
{
|
||||
return m_player->playbackState() == QMediaPlayer::PlayingState;
|
||||
}
|
||||
|
||||
void Player::handleMediaStatusChanged(QMediaPlayer::MediaStatus status)
|
||||
{
|
||||
if (status == QMediaPlayer::EndOfMedia && onEnd)
|
||||
onEnd();
|
||||
}
|
||||
|
||||
} // namespace Uos
|
||||
Reference in new issue
Block a user