Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

How to set mpris2 music data?

by morgon (Deacon)
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.

Comment on How to set mpris2 music data?
Select or Download Code
Re: How to set mpris2 music data?
by kcott (Abbot) 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
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (19)
As of 2014-10-30 17:55 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (208 votes), past polls