Add volume control

This commit is contained in:
Anika Raemer 2021-03-14 14:42:32 +01:00
parent 5d5e3c6888
commit 4a83f971f3
14 changed files with 144 additions and 32 deletions

View file

@ -10,17 +10,20 @@ MusicController::MusicController(QObject *parent) : QObject(parent)
mVlc = new VlcInstance(VlcCommon::args(), this);
mModel = new MusicModel(mVlc, this);
mPlayer = new VlcMediaListPlayer(mVlc);
mVlcAudio = new VlcAudio(mPlayer->mediaPlayer());
connect(mModel, &MusicModel::navigateTo, this, &MusicController::navigateTo);
connect(mModel, &MusicModel::navigateTo, [this](NavigationItemModel*){
if(mModel->isPlaying()) mModel->playPause();
connect(mModel, &MusicModel::navigateTo, this, &MusicController::onNavigationRequest);
//connect(mModel, &MusicModel::play, mPlayer, &VlcMediaListPlayer::play);
connect(mModel, &MusicModel::play, [this](){
mVlcAudio->setVolume(mModel->getAudioVolume());
mPlayer->play();
});
connect(mModel, &MusicModel::play, mPlayer, &VlcMediaListPlayer::play);
connect(mModel, &MusicModel::stop, mPlayer, &VlcMediaListPlayer::stop);
connect(mModel, &MusicModel::previous, mPlayer, &VlcMediaListPlayer::previous);
connect(mModel, &MusicModel::next, mPlayer, &VlcMediaListPlayer::next);
connect(mModel, &MusicModel::pause, mPlayer->mediaPlayer(), &VlcMediaPlayer::pause);
connect(mModel, &MusicModel::audioVolumeChanged, mVlcAudio, &VlcAudio::setVolume);
connect(mPlayer, SIGNAL(nextItemSet(VlcMedia*)), mModel, SLOT(onNextMediaSet(VlcMedia*)));
connect(mPlayer->mediaPlayer(), &VlcMediaPlayer::lengthChanged, mModel, &MusicModel::onLengthChanged);
@ -33,6 +36,7 @@ MusicController::MusicController(QObject *parent) : QObject(parent)
MusicController::~MusicController()
{
mPlayer->deleteLater();
mVlcAudio->deleteLater();
}
void MusicController::initPlayer(NavigationItemModel *item)
@ -58,3 +62,11 @@ void MusicController::setContextProperties()
if(!mContext) return;
mContext->setContextProperty("musicModel", mModel);
}
void MusicController::onNavigationRequest(NavigationItemModel *item)
{
if(mModel->isPlaying()) {
mModel->playPause();
}
emit navigateTo(item);
}

View file

@ -8,6 +8,7 @@
#include <VLCQtCore/Common.h>
#include <VLCQtCore/Instance.h>
#include <VLCQtCore/MediaListPlayer.h>
#include <VLCQtCore/Audio.h>
class MusicModel;
@ -31,12 +32,21 @@ private:
QQmlContext* mContext = Q_NULLPTR;
MusicModel* mModel;
MusicModel* mModel = Q_NULLPTR;
VlcInstance* mVlc;
VlcMediaListPlayer* mPlayer;
VlcInstance* mVlc = Q_NULLPTR;
VlcMediaListPlayer* mPlayer = Q_NULLPTR;
VlcAudio* mVlcAudio = Q_NULLPTR;
bool mIsMediaListSet = false;
private slots:
/**
* @brief Stop player if necessary and forward signal navigatTo
* @param item target of navigation request
* @see navigateTo(NavigationItemModel* item);
*/
void onNavigationRequest(NavigationItemModel* item);
};
#endif // MUSICCONTROLLER_H