Class: MPRIS::TrackList

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

Overview

This class represents the Media Player's tracklist.

Note that if player.has_tracklist? is false, the methods described below will be implemented as no-ops, except metadata (which is valid only if given argument is 0), current_track (which always returns 0), length (which will return 0 or 1), and add_track.

Instance Method Summary collapse

Constructor Details

#initialize(service, parent) ⇒ TrackList

A tracklist object should only be created directly by its parent MPRIS


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mpris/tracklist.rb', line 22

def initialize( service, parent ) #:nodoc:
  @service = service
  @parent = parent

  # Check the service implements the MediaPlayer interface
  object = @service.object("/TrackList")
  object.introspect
  unless object.has_iface? MPRIS::MPRIS_INTERFACE
    raise(MPRIS::InterfaceNotImplementedException, 
      "#{@service.name} does not implement the MediaPlayer interface on /TrackList.")
  end
  @interface = object[MPRIS::MPRIS_INTERFACE]
end

Instance Method Details

#add_track(uri, play_immediately = false) ⇒ Object

Appends an URI in the TrackList.

Returns 0 if successful

Raises:

  • (ArgumentError)

61
62
63
64
# File 'lib/mpris/tracklist.rb', line 61

def add_track(uri,play_immediately=false)
  raise(ArgumentError,"'uri' argument cannot be nil") if uri.nil?
  @interface.AddTrack(uri,play_immediately)
end

#current_trackObject

Return the position of current URI in the TrackList The return value is zero-based, so the position of the first URI in the TrackList is 0. The behavior of this method is unspecified if there are zero items in the TrackList.


49
50
51
# File 'lib/mpris/tracklist.rb', line 49

def current_track
  return @interface.GetCurrentTrack.first
end

#delete_allObject

Removes all tracks from the TrackList.


75
76
77
78
79
80
81
# File 'lib/mpris/tracklist.rb', line 75

def delete_all
  len = length
  while(len) do
    delete_track(0)
    len -= 1
  end
end

#delete_track(pos) ⇒ Object

Removes an URI from the TrackList.

pos is the position in the tracklist of the item to remove.

Raises:

  • (ArgumentError)

69
70
71
72
# File 'lib/mpris/tracklist.rb', line 69

def delete_track(pos)
  raise(ArgumentError,"'pos' argument cannot be nil") if pos.nil?
  @interface.DelTrack(pos)
end

#lengthObject

Returns the number of items in the TrackList.


54
55
56
# File 'lib/mpris/tracklist.rb', line 54

def length
  return @interface.GetLength.first
end

#loopObject

Returns tracklist looping status.


90
91
92
93
94
95
# File 'lib/mpris/tracklist.rb', line 90

def loop
  # Hack to get the player interface
  player_iface = @parent.player.send(:interface)
  # Fourth integrer in array is the looping status
  return player_iface.GetStatus.first[3] #== 1
end

#loop=(bool) ⇒ Object

Set the tracklist looping status. true to loop, false to stop looping.

Raises:

  • (ArgumentError)

84
85
86
87
# File 'lib/mpris/tracklist.rb', line 84

def loop=(bool)
  raise(ArgumentError,"'bool' argument cannot be nil") if bool.nil?
  @interface.SetLoop(bool)
end

#metadata(pos) ⇒ Object

Gives all metadata available for item at given position in the TrackList, counting from 0.

Metadata is returned as key,values pairs in a Hash

The pos argument is the position in the TrackList of the item of which the metadata is requested.

Raises:

  • (ArgumentError)

41
42
43
44
# File 'lib/mpris/tracklist.rb', line 41

def (pos)
  raise(ArgumentError,"'pos' argument cannot be nil") if pos.nil?
  return @interface.(pos).first
end

#randomObject

Returns the tracklist shuffle / random status.


105
106
107
108
109
110
# File 'lib/mpris/tracklist.rb', line 105

def random
  # Hack to get the player interface
  player_iface = @parent.player.send(:interface)
  # Second integrer in array is the random status
  return player_iface.GetStatus.first[1] #== 1
end

#random=(bool) ⇒ Object

Set the tracklist shuffle / random status. It may or may not play tracks only once. true to play randomly / shuffle tracklist, false to play normally / reorder tracklist.

Raises:

  • (ArgumentError)

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

def random=(bool)
  raise(ArgumentError,"'bool' argument cannot be nil") if bool.nil?
  @interface.SetRandom(bool)
end