Class: MPRIS

Inherits:
Object
  • Object
show all
Defined in:
lib/mpris.rb,
lib/mpris/tracklist.rb

Overview

MPRIS is the Media Player Remote Interfacing Specification.

Author

Nicholas J Humfrey ([email protected])

Copyright

Copyright © 2008 Nicholas J Humfrey

License

Distributes under the same terms as Ruby

Defined Under Namespace

Classes: InterfaceNotImplementedException, ServiceNotFoundException, TrackList

Constant Summary collapse

MPRIS_SERVICE_PREFIX =
'org.mpris'
MPRIS_INTERFACE =
'org.freedesktop.MediaPlayer'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dbus_address = nil, service_name = nil) ⇒ MPRIS

Create a new MPRIS instance. By default it will return the first MPRIS enabled player found on the Session Bus.

The dbus_address parameter can be use to specify a different dbus, for example 'unix:path=/var/run/dbus_socket'.

The service_name parameter can be used to specify a specifc MediaPlayer, for example 'org.mpris.vlc'.


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mpris.rb', line 33

def initialize( dbus_address=nil, service_name=nil )

  # FIXME: support passing in a dbus object, instead of a dbus address
  if dbus_address.nil?
    # Use the default session bus
    @dbus = DBus::SessionBus.instance
  else
    @dbus = DBus::Connection.new(dbus_address)
    @dbus.connect
    #self.send_hello
  end
  
  # Look for service name, if one isn't given
  if service_name.nil?
    service_names = @dbus.proxy.ListNames[0]
    service_names.each { |n|
      if (n =~ /^org.mpris/)
        service_name = n
        break
      end
    }
    
    # Did we find one?
    if service_name.nil?
      raise( ServiceNotFoundException, "No MPRIS service found on D-Bus." )
    end
  end
  
  # Get the service
  @service = @dbus.service(service_name)
  if @service.nil?
    raise( ServiceNotFoundException, "MPRIS service '#{service_name}' not found on D-Bus." )
  end
  
  # Check the service implements the MediaPlayer interface
  root_object = @service.object("/")
  root_object.introspect
  unless root_object.has_iface? MPRIS_INTERFACE
    raise(InterfaceNotImplementedException, 
      "#{@service.name} does not implement the MediaPlayer interface on /." )
  end
  @interface = root_object[MPRIS_INTERFACE]
  
  # Create the player object
  @player = MPRIS::Player.new(@service, self)
  
  # Create a tracklist object
  @tracklist = MPRIS::TrackList.new(@service, self)
end

Instance Attribute Details

#playerObject (readonly)

Returns the value of attribute player


18
19
20
# File 'lib/mpris.rb', line 18

def player
  @player
end

#tracklistObject (readonly)

Returns the value of attribute tracklist


19
20
21
# File 'lib/mpris.rb', line 19

def tracklist
  @tracklist
end

Instance Method Details

#identityObject

Identify the “media player” as in “VLC 0.9.0”, “bmpx 0.34.9”, “Audacious 1.4.0” …

Returns a string containing the media player identification.


90
91
92
# File 'lib/mpris.rb', line 90

def identity
  return @interface.Identity
end

#inspectObject

:nodoc:


83
84
85
# File 'lib/mpris.rb', line 83

def inspect # :nodoc:
  return %Q(#<MPRIS: local_name="#{@dbus.unique_name}", remote_name="#{@service.name}">)
end

#mpris_versionObject

Returns the version of the MPRIS spec being implemented as major.major


100
101
102
# File 'lib/mpris.rb', line 100

def mpris_version
  return @interface.MprisVersion.first.join('.')
end

#quitObject

Makes the “Media Player” exit.


95
96
97
# File 'lib/mpris.rb', line 95

def quit
  @interface.Quit
end