Mostly reimplement Player, begin implementing ViewPlayer UI design

This commit is contained in:
Dark Steveneq
2025-10-17 22:29:12 +02:00
parent c99efcf9e3
commit 63d9c21e98
6 changed files with 158 additions and 86 deletions

View File

@@ -2,8 +2,11 @@
// Public
Player::Player(QObject *parent) : QObject(parent),
player(this),
output(this)
player(this), output(this), timer(this), m_currentIndex(0), m_stations({
Station{"Autoradio", "autoradio", "", 0},
Station{"Live Mix", "live", "", 0},
Station{"Bass Boosted", "bassboosted", "", 0}
})
{
QObject::connect(&this->player, &QMediaPlayer::playbackStateChanged, this, [this] () {
qDebug("Player::Player()->Lambda: Playing got changed!");
@@ -15,9 +18,19 @@ Player::Player(QObject *parent) : QObject(parent),
emit this->volumeChanged();
});
this->output.setVolume(0.3);
this->timer.start(metadataFetchTimeout);
QObject::connect(&this->timer, &QTimer::timeout, this, [this] () {
qDebug("Player::Player()->Lambda: Timer triggered!");
if (this->m_currentIndex > -1)
{
emit this->currentStationChanged();
}
emit this->stationsChanged();
});
this->output.setVolume(0.2);
this->player.setAudioOutput(&this->output);
qDebug("Player::Player(): Constructed");
}
@@ -42,11 +55,30 @@ void Player::setVolume(float newVolume)
this->output.setVolume(newVolume);
}
const QList<Station> Player::stations() const
{
return this->m_stations;
}
const int Player::currentIndex() const
{
return this->m_currentIndex;
}
const Station* Player::currentStation() const
{
if (this->m_currentIndex < 0 || this->m_currentIndex >= this->m_stations.length())
{
qWarning("Player::currentStation(): Tried accessing out of bounds.");
return nullptr;
}
return &this->m_stations[this->m_currentIndex];
}
// Public slots
void Player::startPlaying(u_int8_t index)
{
if (index < 0 || index >= maxStations)
if (index < 0 || index >= this->m_stations.length())
{
qWarning("Player::startPlaying(): Tried accessing out of bounds.");
return;
@@ -54,19 +86,28 @@ void Player::startPlaying(u_int8_t index)
if (this->playing()) {
this->stopPlaying();
}
this->player.setSource(QUrl(streamPrefix + stations[index].slug));
this->m_currentIndex = index;
emit this->currentIndexChanged();
emit this->currentStationChanged();
this->player.setSource(QUrl("https://youradio.nonamesoft.xyz/youradio/api/" + this->m_stations[index].m_slug));
this->player.play();
qDebug("Player::startPlaying(): Starting playing");
}
void Player::stopPlaying()
{
if (this->playing())
if (!this->playing())
{
qWarning("Player::stopPlaying(): Prevented redundant stopPlaying() call.");
return;
}
this->player.stop();
this->player.setSource(QUrl(""));
this->m_currentIndex = -1;
emit this->currentIndexChanged();
emit this->currentStationChanged();
qDebug("Player::stopPlaying(): Stopping playback...");
}
}