Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

How to set mpris2 music data?

by morgon (Curate)
on Apr 23, 2014 at 22:52 UTC ( #1083483=perlquestion: print w/replies, xml ) Need Help??
morgon has asked for the wisdom of the Perl Monks concerning the following question:


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.

Replies are listed 'Best First'.
Re: How to set mpris2 music data?
by kcott (Chancellor) on Apr 24, 2014 at 10:05 UTC

    G'day morgon,

    This isn't an area I'm familiar with (I can't help you with the application); however, I thought I'd point out the tutorials, and related information, linked from the Net::DBus::Tutorial page.

    -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1083483]
Approved by Old_Gray_Bear
[choroba]: use C instead of H to get the decimal number
[erix]: ( no love like f love )
[choroba]: f* love

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-02-20 16:38 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (272 votes). Check out past polls.