Use QMediaPlayer instead of bass for music
This commit is contained in:
parent
355bd1dbbb
commit
bd5ac3ea21
@ -4,32 +4,23 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app)
|
||||
{
|
||||
m_parent = parent;
|
||||
ao_app = p_ao_app;
|
||||
m_player = new QMediaPlayer;
|
||||
}
|
||||
|
||||
AOMusicPlayer::~AOMusicPlayer()
|
||||
{
|
||||
BASS_ChannelStop(m_stream);
|
||||
m_player->stop();
|
||||
}
|
||||
|
||||
void AOMusicPlayer::play(QString p_song)
|
||||
{
|
||||
BASS_ChannelStop(m_stream);
|
||||
|
||||
QString f_path = ao_app->get_music_path(p_song);
|
||||
|
||||
m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE);
|
||||
|
||||
this->set_volume(m_volume);
|
||||
|
||||
BASS_ChannelPlay(m_stream, false);
|
||||
m_player->setMedia(QUrl::fromLocalFile(ao_app->get_music_path(p_song)));
|
||||
this->set_volume(50);
|
||||
m_player->play();
|
||||
}
|
||||
|
||||
void AOMusicPlayer::set_volume(int p_value)
|
||||
{
|
||||
m_volume = p_value;
|
||||
|
||||
float volume = m_volume / 100.0f;
|
||||
|
||||
BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume);
|
||||
|
||||
m_player->setVolume(p_value);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QWidget>
|
||||
#include <string.h>
|
||||
#include <QDebug>
|
||||
#include <QMediaPlayer>
|
||||
|
||||
class AOMusicPlayer
|
||||
{
|
||||
@ -21,6 +22,7 @@ private:
|
||||
QWidget *m_parent;
|
||||
AOApplication *ao_app;
|
||||
|
||||
QMediaPlayer *m_player;
|
||||
int m_volume = 0;
|
||||
HSTREAM m_stream;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user