summaryrefslogtreecommitdiffstats
path: root/playerwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'playerwidget.cpp')
-rw-r--r--playerwidget.cpp46
1 files changed, 46 insertions, 0 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<const QStandardItemModel*>(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<void(QMediaObject::*)(const QString &, const QVariant &)>(&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<void(QMediaObject::*)(const QString &, const QVariant &)>(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange);
+ connect(mPlayer, static_cast<void(QMediaObject::*)(const QString &, const QVariant &)>(&QMediaObject::metaDataChanged), this, &PlayerWidget::doMetadataChange);
mPlayer->setMedia(QUrl(url));
mPlayer->play();
}