Hi

I have a gnome-shell extension that displays artist and title of the current song in the top bar.

This extension gets the information via mpris2 (a d-bus interface) that is currently fed by cantana (a mpd-client) that controls a mpd-player on a remote machine.

This works nicely for local content, but not for streams because then (for whatever reason) cantata does not seem to feed the mpris2-interface.

As the strings that cantata receives from mpd need to be a bit mangled anyway I now want to replace cantanta with a Perl-script of my own.

I have figured out how to receive the information I want to display from mpd, but at the moment I cannot figure out how to feed it into the d-bus.

So my question is this: Given an artist and a title (both are strings), how can I feed this data into the mpris2 interface so that it can be properly displayed?

What I have figured out is how to do the opposite (i.e. retrieving artist/title from mpris2) like this:

use strict; use Net::DBus; use Data::Dumper; my $bus = Net::DBus->find; my $service = $bus->get_service("org.mpris.MediaPlayer2.cantata"); my $mpris = $service->get_object("/org/mpris/MediaPlayer2"); my $output = $mpris->Get('org.mpris.MediaPlayer2.Player', "Metadata"); print Dumper($output);
This prints e.g.:
$VAR1 = { 'mpris:length' => 287000000, 'xesam:title' => 'Giant Steps', 'xesam:album' => 'Giant Steps', 'mpris:artUrl' => 'file:///home/mh/.cache/cantata/covers/Joh +n Coltrane/Giant Steps.png', 'xesam:artist' => [ 'John Coltrane' ], 'xesam:genre' => [ 'Unknown' ], 'mpris:trackid' => '/com/googlecode/cantata/Track/11', 'xesam:trackNumber' => 1 };
What I guess I need to do is to implement a d-bus service that implements the proper interfaces and provides a "Metadata"-property where I would then put artist and title information but at the moment I don't know how to do that.

Any help is greatly appreciated.


In reply to How to set mpris2 music data? by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.