linuxvlcdbusgdbus

How to set parameters of Mpris SetPosition method


I currently working on controlling VLC player via DBUS. VLC implements MPRIS. There is a method which is named SetPosition of the MPRIS to set the position of the player. It has the following signuture.

SetPosition (o: TrackId, x: Position)

I understand the second argument, but which value should be set for the first argument ? How to set the position of the current video on the player ?

What is the syntax of the SetPosition with dbus-send command ?


Solution

  • The information should be available from the Metadata property as the mpris:trackid field.

    https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Metadata

    Using the Totem player it didn't give me a trackid in the Metadata

    $ dbus-send --session --dest=org.mpris.MediaPlayer2.totem --print-reply /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata
    
    
    method return time=1687072387.945098 sender=:1.236 -> destination=:1.269 serial=365 reply_serial=2
       variant       array [
             dict entry(
                string "mpris:length"
                variant                int64 1416
             )
             dict entry(
                string "xesam:trackNumber"
                variant                uint32 0
             )
          ]
    
    

    So I used / as the object path which worked:

    $ dbus-send --session --dest=org.mpris.MediaPlayer2.totem --type=method_call /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.SetPosition objpath:/ int64:0
    

    If I queried the player in my Firefox session then it gave the following for Metadata which did include a trackid object path:

    $ dbus-send --session --dest=org.mpris.MediaPlayer2.firefox.instance2129 --print-reply /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata
    
    
    method return time=1687072613.024171 sender=:1.106 -> destination=:1.271 serial=94 reply_serial=2
       variant       array [
             dict entry(
                string "mpris:trackid"
                variant                object path "/org/mpris/MediaPlayer2/firefox"
             )
             dict entry(
                string "xesam:title"
                variant                string "Rick Astley - Never Gonna Give You Up (Official Music Video)"
             )
             dict entry(
                string "xesam:album"
                variant                string ""
             )
             dict entry(
                string "xesam:artist"
                variant                array [
                      string "Rick Astley"
                   ]
             )
          ]