Skip to content

Commit

Permalink
fix: 切换默认link
Browse files Browse the repository at this point in the history
切换默认link

Bug: https://pms.uniontech.com/bug-view-273295.html
Log: 切换默认link
  • Loading branch information
myk1343 authored and deepin-bot[bot] committed Sep 18, 2024
1 parent 9f9b84f commit a32b21d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/backends/mpv/mpv_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,9 @@ void MpvProxy::handle_mpv_events()
.arg(my_get_property(m_handle, "video-dec-params/rotate").toInt())
.arg(my_get_property(m_handle, "video-params/rotate").toInt());
m_bLoadMedia = false;
if(utils::check_wayland_env()) {
dmr::utils::switchToDefaultSink();
}
break;
}
case MPV_EVENT_VIDEO_RECONFIG: {
Expand Down
80 changes: 80 additions & 0 deletions src/libdmr/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,5 +575,85 @@ void getPlayProperty(const char *path, QMap<QString, QString> *&proMap)
qWarning() << __func__ << "file path error!!!!!";
}
}

QVariant redDBusProperty(const QString &sService, const QString &sPath, const QString &sInterface, const char *pPropert)
{
// 创建QDBusInterface接口
QDBusInterface ainterface(sService, sPath,
sInterface,
QDBusConnection::sessionBus());
if (!ainterface.isValid()) {
QVariant v(0) ;
return v;
}
//调用远程的value方法
QVariant v = ainterface.property(pPropert);
return v;
}

void switchToDefaultSink()
{

QVariant v = redDBusProperty("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio",
"com.deepin.daemon.Audio", "SinkInputs");

if (!v.isValid())
return;

QList<QDBusObjectPath> allSinkInputsList = v.value<QList<QDBusObjectPath>>();

int inputIndex = -1; //当前音乐的索引值
int curSinkIndex = -1;
for (auto curPath : allSinkInputsList) {
QVariant nameV = redDBusProperty("com.deepin.daemon.Audio", curPath.path(),
"com.deepin.daemon.Audio.SinkInput", "Name");

if (!nameV.isValid() || nameV.toString() != QObject::tr("Movie"))
continue;
QString path = curPath.path();
int indx = path.lastIndexOf("/");
path = path.mid(indx + 1, path.size() - indx); //最后一个'/',然后移出Sink关键字
if (path.size() > 9) {
inputIndex = path.remove(0, 9).toInt();
//break;
} else
return;

QVariant sinkV = redDBusProperty("com.deepin.daemon.Audio", curPath.path(),
"com.deepin.daemon.Audio.SinkInput", "SinkIndex");
if (!sinkV.isValid())
continue;
curSinkIndex = sinkV.toInt();
}

if (inputIndex == -1)
return;

//获取默认输出设备
QVariant varsink = redDBusProperty("com.deepin.daemon.Audio", "/com/deepin/daemon/Audio",
"com.deepin.daemon.Audio", "DefaultSink");
if (!varsink.isValid())
return;
QString sinkpath = varsink.value<QDBusObjectPath >().path();
int sinkindex = sinkpath.lastIndexOf("/");
sinkpath = sinkpath.mid(sinkindex + 1, sinkpath.size() - sinkindex);//最后一个'/'
if (sinkpath.size() > 4) {
sinkindex = sinkpath.remove(0, 4).toInt();
} else
return;

qInfo() <<"default sink: " << sinkindex << "\tcurrent sink: " << curSinkIndex << "\tsink input index: " << inputIndex;

if (curSinkIndex == sinkindex) {
return;
}
QProcess proc;
QStringList sList;
sList.append("move-sink-input");
sList.append(QString::number(inputIndex));
sList.append(QString::number(sinkindex));
proc.start("pacmd", sList);
proc.waitForFinished();
}
}
}
1 change: 1 addition & 0 deletions src/libdmr/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ QString ElideText(const QString &text, const QSize &size,
* @param 配置保存的map
*/
void getPlayProperty(const char *path, QMap<QString, QString> *&proMap);
void switchToDefaultSink();
}
}

Expand Down

0 comments on commit a32b21d

Please sign in to comment.