From 4712646d24997ace16b2894c92137c7efbac89a0 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 26 Aug 2017 12:01:10 +0200 Subject: Make WebRadio stuff work! Display stream Metadata and add songs to playlist. Make sure that nothing happens when you doubleclick on a Webradio song in there. --- playerwidget.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ playerwidget.h | 9 +++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/playerwidget.cpp b/playerwidget.cpp index 3dd8b87..7f81bcc 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -285,6 +285,9 @@ void PlayerWidget::setupGui(){ rightWidgetL->addWidget(playListGB); rightWidget->setLayout(rightWidgetL); + //stream data + connect(this, &PlayerWidget::streamDataNeedsUpdate, this, &PlayerWidget::updateStreamData); + //put it all together QSplitter *splitter = new QSplitter; splitter->addWidget(leftWidget); @@ -806,6 +809,7 @@ void PlayerWidget::doModelChanged(){ } void PlayerWidget::viewDoubleClicked(const QModelIndex &idx){ + mPlayer->stop(); const QStandardItemModel *model = static_cast(idx.model()); if(model == mViewModel || model == mSearchModel){ addToPlayList(); @@ -813,6 +817,9 @@ void PlayerWidget::viewDoubleClicked(const QModelIndex &idx){ } if(model == mWebRadioModel){ QString url(idx.data(UrlRole).toString()); + mPlayListModel->clear(); + mPlayListModel->setHorizontalHeaderLabels(QStringList() << tr("Title")); + mRightTE->clear(); playUrl(url); return; } @@ -1258,6 +1265,10 @@ void PlayerWidget::randomPlay(){ } void PlayerWidget::playCurrent(const QModelIndex &index){ + int isRemote = index.data(RemoteRole).toInt(); + if(isRemote){ + return; + } mPlayer->stop(); QString fullPath = index.data(FullPathRole).toString(); play(fullPath); @@ -1365,7 +1376,40 @@ void PlayerWidget::addWebRadio(){ wrQ.exec(); } +void PlayerWidget::doMetadataChange(const QString &key, const QVariant &value){ + if(key == "Title"){ + QString np = value.toString(); + QStandardItem *plRoot = mPlayListModel->invisibleRootItem(); + QStandardItem *nowP = new QStandardItem; + nowP->setFont(QFont("courier")); + nowP->setEditable(false); + nowP->setIcon(QIcon(":/dog_hood.png")); + nowP->setData(1, RemoteRole); + nowP->setText(np); + plRoot->appendRow(nowP); + QString npString = QString("Title: %1").arg(np); + mCurrentTE->setText(npString); + }else{ + if(mOtherMeta[key] != value){ + mOtherMeta[key] = value; + emit streamDataNeedsUpdate(); + } + } +} + +void PlayerWidget::updateStreamData(){ + QStringList sd; + sd.append(QString("%1: %2").arg("Genre", -16).arg(mOtherMeta.value("Genre").toString())); + sd.append(QString("%1: %2").arg("Publisher", -16).arg(mOtherMeta.value("Publisher").toString())); + sd.append(QString("%1: %2").arg("Location", -16).arg(mOtherMeta.value("location").toString())); + sd.append(QString("%1: %2").arg("Audio Codec", -16).arg(mOtherMeta.value("AudioCodec").toString())); + QString s = sd.join("\n"); + mLeftTE->setText(s); +} + void PlayerWidget::play(const QString &fullPath){ + disconnect(mPlayer, static_cast(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange); + mLeftTE->clear(); mPlayer->setMedia(QUrl::fromLocalFile(fullPath)); TagLib::FileRef file(QString(fullPath).toUtf8()); fillWithText(mCurrentTE, file); @@ -1397,6 +1441,8 @@ void PlayerWidget::play(const QString &fullPath){ } void PlayerWidget::playUrl(const QString &url){ + disconnect(mPlayer, static_cast(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange); + connect(mPlayer, static_cast(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange); mPlayer->setMedia(QUrl(url)); mPlayer->play(); } diff --git a/playerwidget.h b/playerwidget.h index 2fb218a..aeace26 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -27,9 +28,9 @@ class WebDownloader; class PlayerWidget : public QWidget { Q_OBJECT public: - enum ItemType { Artist, Album, Song, Genre }; + enum ItemType { Artist, Album, Song, Genre, WebRadio }; enum PopulateType { FilterType, IdType, EmptyType }; - enum CustomRoles { TypeRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2, FullPathRole = Qt::UserRole + 3, GenreRole = Qt::UserRole + 4, ArtistRole = Qt::UserRole + 5, TitleRole = Qt::UserRole + 6, AlbumRole = Qt::UserRole + 7, LengthRole = Qt::UserRole + 8, UrlRole = Qt::UserRole + 9 }; + enum CustomRoles { TypeRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2, FullPathRole = Qt::UserRole + 3, GenreRole = Qt::UserRole + 4, ArtistRole = Qt::UserRole + 5, TitleRole = Qt::UserRole + 6, AlbumRole = Qt::UserRole + 7, LengthRole = Qt::UserRole + 8, UrlRole = Qt::UserRole + 9, RemoteRole = Qt::UserRole + 10 }; explicit PlayerWidget(QWidget *parent = 0); ~PlayerWidget(); const QMediaPlayer* player() const { return mPlayer; } @@ -73,6 +74,8 @@ class PlayerWidget : public QWidget { void webDlDone(); void filterFromPlaylist(); void addWebRadio(); + void doMetadataChange(const QString &key, const QVariant &value); + void updateStreamData(); void mute(bool triggered); void volumeChanged(int volume); @@ -94,6 +97,7 @@ class PlayerWidget : public QWidget { void message(const QString &msg); void modelChanged(); void setWinTitle(const QString &title); + void streamDataNeedsUpdate(); private: void setupGui(); @@ -151,6 +155,7 @@ class PlayerWidget : public QWidget { bool mStarting; QStackedLayout *mSearchDirStack; WebDownloader *mWebDownloader; + QMap mOtherMeta; }; #endif // PLAYERWIDGET_H -- cgit v1.2.3-70-g09d2