如何获取两个 VLC 实例的目的地

如何获取两个 VLC 实例的目的地

如果您只运行一个 VLC 实例,您可以使用 org.mpris.MediaPlayer2.vlc 作为目标,通过 dbus-send 与 VLC 通信:

$ dbus-send --dest=org.mpris.MediaPlayer2.vlc  ...

如果您有两个正在运行的 VLC 实例,它们具有不同的目标 xxxx 和 yyyy。如果您想与其中之一交谈,则必须使用 xxxx 或 yyyy 作为目的地:

$ dbus-send --dest=:xxxx   ...

我可以通过以下方式找到第一个实例的目的地:

$ dbus-send --print-reply --dest=org.freedesktop.DBus  /org/freedesktop/DBusorg.freedesktop.DBus.ListQueuedOwners  string:org.mpris.MediaPlayer2.vlc

method return time=1702494718.199915 sender=org.freedesktop.DBus -> destination=:1.1256 serial=3 reply_serial=2
   array [
      string ":1.1251"
   ]

然后我看到目的地是1.1251

但是我如何才能获得第二个实例的目的地呢?

答案1

我总是使用busctl来获取完整的dbus信息。
有一个系统总线(busctl --system)和一个会话总线(busctl --user)或完整列表(busctl -l)
输入:

busctl --user | grep "vlc"

然后你会得到这样的东西

:1.641                                              91266 vlc             xxxxx :1.641        session-c2.scope  c2      -
:1.642                                              91266 vlc             xxxxx :1.642        session-c2.scope  c2      -
:1.643                                              91266 vlc             xxxxx :1.643        session-c2.scope  c2      -
:1.644                                              91266 vlc             xxxxx :1.644        session-c2.scope  c2      -
:1.654                                              91361 vlc             xxxxx :1.654        session-c2.scope  c2      -
:1.655                                              91361 vlc             xxxxx :1.655        session-c2.scope  c2      -
:1.656                                              91361 vlc             xxxxx :1.656        session-c2.scope  c2      -
:1.657                                              91361 vlc             xxxxx :1.657        session-c2.scope  c2      -
org.kde.StatusNotifierItem-91266-2                  91266 vlc             xxxxx :1.644        session-c2.scope  c2      -
org.kde.StatusNotifierItem-91361-2                  91361 vlc             xxxxx :1.657        session-c2.scope  c2      -
org.mpris.MediaPlayer2.vlc                          91266 vlc             xxxxx :1.641        session-c2.scope  c2      -
org.mpris.MediaPlayer2.vlc.instance91361            91361 vlc             xxxxx :1.654        session-c2.scope  c2   

org 文件是活动服务。
您会看到有第二个服务名为 org.mpris.MediaPlayer2.vlc.instance91361
第一个 vlc 实例位于 PID 91266 上,第二个 vlc 实例位于 PID 91361 上

在我的示例中调用:

dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListQueuedOwners string:org.mpris.MediaPlayer2.vlc.instance91361

将为您提供有关第二个实例的信息

- - - - - - 顺便一提

您可以检查对象树的 dbus 服务
busctl --user tree org.mpris.MediaPlayer2.vlc.instance91361

你得到:

└─/org
  └─/org/mpris
    └─/org/mpris/MediaPlayer2

那么你也可以内省对象
busctl --user introspect org.mpris.MediaPlayer2.vlc.instance91361 /org/mpris/MediaPlayer2

输出:

NAME                                TYPE      SIGNATURE RESULT/VALUE                             FLAGS
org.freedesktop.DBus.Introspectable interface -         -                                        -
.Introspect                         method    -         s                                        -
org.freedesktop.DBus.Properties     interface -         -                                        -
.Get                                method    ss        v                                        -
.GetAll                             method    s         a{sv}                                    -
.Set                                method    ssv       -                                        -
.PropertiesChanged                  signal    sa{sv}as  -                                        -
org.mpris.MediaPlayer2              interface -         -                                        -
.Quit                               method    -         -                                        -
.Raise                              method    -         -                                        -
.CanQuit                            property  b         true                                     emits-change
.CanRaise                           property  b         false                                    emits-change
.CanSetFullscreen                   property  b         false                                    emits-change
.DesktopEntry                       property  s         "vlc"                                    emits-change
.Fullscreen                         property  b         false                                    emits-change writable
.HasTrackList                       property  b         false                                    emits-change
.Identity                           property  s         "VLC media player"                       emits-change
.SupportedMimeTypes                 property  as        29 "audio/mpeg" "audio/x-mpeg" "video/m… emits-change
.SupportedUriSchemes                property  as        21 "file" "http" "https" "rtsp" "realrt… emits-change
org.mpris.MediaPlayer2.Player       interface -         -                                        -
.Next                               method    -         -                                        -
.OpenUri                            method    s         -                                        -
.Pause                              method    -         -                                        -
.Play                               method    -         -                                        -
.PlayPause                          method    -         -                                        -
.Previous                           method    -         -                                        -
.Seek                               method    x         -                                        -
.SetPosition                        method    ox        -                                        -
.Stop                               method    -         -                                        -
.CanControl                         property  b         true                                     emits-change
.CanPause                           property  b         false                                    emits-change
.CanPlay                            property  b         false                                    emits-change
.CanSeek                            property  b         false                                    emits-change
.LoopStatus                         property  s         "None"                                   emits-change writable
.MaximumRate                        property  d         32                                       emits-change writable
.Metadata                           property  a{sv}     0                                        emits-change
.MinimumRate                        property  d         0.032                                    emits-change writable
.PlaybackStatus                     property  s         "Stopped"                                emits-change
.Position                           property  i         0                                        emits-change
.Rate                               property  d         1                                        emits-change writable
.Shuffle                            property  d         false                                    emits-change writable
.Volume                             property  d         0                                        emits-change writable
org.mpris.MediaPlayer2.TrackList    interface -         -                                        -
.AddTrack                           method    sob       -                                        -
.GetTracksMetadata                  method    ao        aa{sv}                                   -
.GoTo                               method    o         -                                        -
.RemoveTrack                        method    o         -                                        -
.CanEditTracks                      property  b         true                                     emits-change
.Tracks                             property  ao        0                                        emits-change
.TrackAdded                         signal    a{sv}o    -                                        -
.TrackListReplaced                  signal    aoo       -                                        -
.TrackMetadataChanged               signal    oa{sv}    -                                        -
.TrackRemoved                       signal    o         -                                        -

您会看到所有定义的接口和方法。

例如,让我们从接口中获取“OpenUri”方法:org.mpris.MediaPlayer2.Player

busctl --user call org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player OpenUri s "your url"
-- 将首先打开视频

busctl --user call org.mpris.MediaPlayer2.vlc.instance91361 /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player OpenUri s "your url"
-- 将在第二次打开视频

call 语法:
============
call SERVICE OBJECT INTERFACE METHOD [SIGNATURE [ARGUMENT...]]
了解更多信息 - 请参阅busctl - 帮助

祝你今天过得愉快!

相关内容