qt music
This commit is contained in:
parent
71da60b5d6
commit
1514ffea6a
@ -1,13 +1,18 @@
|
|||||||
#ifndef AOMUSICPLAYER_H
|
#ifndef AOMUSICPLAYER_H
|
||||||
#define AOMUSICPLAYER_H
|
#define AOMUSICPLAYER_H
|
||||||
|
|
||||||
|
#if defined(BASSAUDIO)
|
||||||
#include "bass.h"
|
#include "bass.h"
|
||||||
|
#elif defined(QTAUDIO)
|
||||||
|
#include <QMediaPlayer>
|
||||||
|
#endif
|
||||||
#include "aoapplication.h"
|
#include "aoapplication.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#if defined(BASSAUDIO)
|
||||||
class AOMusicPlayer
|
class AOMusicPlayer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -24,5 +29,37 @@ private:
|
|||||||
int m_volume = 0;
|
int m_volume = 0;
|
||||||
HSTREAM m_stream;
|
HSTREAM m_stream;
|
||||||
};
|
};
|
||||||
|
#elif defined(QTAUDIO)
|
||||||
|
class AOMusicPlayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app);
|
||||||
|
~AOMusicPlayer();
|
||||||
|
|
||||||
|
void play(QString p_song);
|
||||||
|
void set_volume(int p_value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMediaPlayer m_player;
|
||||||
|
QWidget *m_parent;
|
||||||
|
AOApplication *ao_app;
|
||||||
|
|
||||||
|
int m_volume = 0;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
class AOMusicPlayer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app);
|
||||||
|
~AOMusicPlayer();
|
||||||
|
|
||||||
|
void play(QString p_song);
|
||||||
|
void set_volume(int p_value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QWidget *m_parent;
|
||||||
|
AOApplication *ao_app;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // AOMUSICPLAYER_H
|
#endif // AOMUSICPLAYER_H
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "aomusicplayer.h"
|
#include "aomusicplayer.h"
|
||||||
|
|
||||||
|
#if defined(BASSAUDIO)
|
||||||
AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
||||||
{
|
{
|
||||||
m_parent = parent;
|
m_parent = parent;
|
||||||
@ -8,14 +9,11 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
|||||||
|
|
||||||
AOMusicPlayer::~AOMusicPlayer()
|
AOMusicPlayer::~AOMusicPlayer()
|
||||||
{
|
{
|
||||||
#ifdef BASSAUDIO
|
|
||||||
BASS_ChannelStop(m_stream);
|
BASS_ChannelStop(m_stream);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOMusicPlayer::play(QString p_song)
|
void AOMusicPlayer::play(QString p_song)
|
||||||
{
|
{
|
||||||
#ifdef BASSAUDIO
|
|
||||||
BASS_ChannelStop(m_stream);
|
BASS_ChannelStop(m_stream);
|
||||||
|
|
||||||
QString f_path = ao_app->get_music_path(p_song);
|
QString f_path = ao_app->get_music_path(p_song);
|
||||||
@ -27,14 +25,63 @@ void AOMusicPlayer::play(QString p_song)
|
|||||||
if (ao_app->get_audio_output_device() != "default")
|
if (ao_app->get_audio_output_device() != "default")
|
||||||
BASS_ChannelSetDevice(m_stream, BASS_GetDevice());
|
BASS_ChannelSetDevice(m_stream, BASS_GetDevice());
|
||||||
BASS_ChannelPlay(m_stream, false);
|
BASS_ChannelPlay(m_stream, false);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AOMusicPlayer::set_volume(int p_value)
|
void AOMusicPlayer::set_volume(int p_value)
|
||||||
{
|
{
|
||||||
m_volume = p_value;
|
m_volume = p_value;
|
||||||
float volume = m_volume / 100.0f;
|
float volume = m_volume / 100.0f;
|
||||||
#ifdef BASSAUDIO
|
|
||||||
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);
|
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#elif defined(QTAUDIO)
|
||||||
|
AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
||||||
|
{
|
||||||
|
m_parent = parent;
|
||||||
|
ao_app = p_ao_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
AOMusicPlayer::~AOMusicPlayer()
|
||||||
|
{
|
||||||
|
m_player.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOMusicPlayer::play(QString p_song)
|
||||||
|
{
|
||||||
|
m_player.stop();
|
||||||
|
|
||||||
|
QString f_path = ao_app->get_music_path(p_song);
|
||||||
|
|
||||||
|
m_player.setMedia(QUrl::fromLocalFile(f_path));
|
||||||
|
|
||||||
|
this->set_volume(m_volume);
|
||||||
|
|
||||||
|
m_player.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOMusicPlayer::set_volume(int p_value)
|
||||||
|
{
|
||||||
|
m_volume = p_value;
|
||||||
|
m_player.setVolume(m_volume);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
||||||
|
{
|
||||||
|
m_parent = parent;
|
||||||
|
ao_app = p_ao_app;
|
||||||
|
}
|
||||||
|
|
||||||
|
AOMusicPlayer::~AOMusicPlayer()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOMusicPlayer::play(QString p_song)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AOMusicPlayer::set_volume(int p_value)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user