This Gem provides a way to control media players using the D-Bus Media Player Remote Interfacing Specification (MPRIS) version 2
Switch branches/tags
Nothing to show
Clone or download
Latest commit bf8f720 Nov 29, 2011

README.rdoc

This Gem provides a way to control media players using the D-Bus Media Player Remote Interfacing Specification (MPRIS) version 2, whose spec can be found at www.mpris.org/2.1/spec:

The Media Player Remote Interfacing Specification is a standard D-Bus interface which aims to provide a common programmatic API for controlling media players. It provides a mechanism for discovery, querying and basic playback control of compliant media players, as well as a tracklist interface which is used to add context to the active media item.

At the moment is under development so take in account backwards incompatible changes may occur. Currently implements the four MPRISv2 interfaces:

  • org.mpris.MediaPlayer2,

  • org.mpris.MediaPlayer2.Player

  • org.mpris.MediaPlayer2.TrackList

  • org.mpris.MediaPlayer2.Playlists

It heavily uses the dbus gem: github.com/sdague/ruby-dbus.

Installation

ruby-mpris2 is not available in any gems repository yet, nor have a Rakefile, so you must build and install it manually:

# 1 - Clone the repository and cd into your local copy
git clone git://github.com/fcingolani/ruby-mpris2.git
cd ruby-mpris2

# 2 - Build the gem
gem build mpris2.gemspec

# 3 - Install mpris2. Will install dbus gem too if not installed yet.
sudo gem install mpris2-0.0.2.gem

Basic Usage

This gem is really easy to use:

require 'mpris2'
require 'pp'

# Get a mediaplayer
mp = MPRIS2.find_media_players.first

# Output current track info
puts "You are currently using #{mp.identity}"
pp mp.metadata

# Play the next song
mp.next

# Decrease the volume to 50%
mp.volume = 0.50

You will find more examples inside the “examples” directory.

Handling signals

You can handle D-Bus signals registering callbacks using “on_” methods, and then running a D-Bus loop:

mp = MPRIS2.find_media_players.first

# We register a callback for the Seeked signal.
mp.on_seeked do | position |
  puts "Seeked to #{position}"
end

# Run the loop. This is a blocking call!
mp.run_loop

# Now try changing your track's position and see on_seeked in action.

License

Copyright (C) 2011 by Federico Cingolani

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.