class Plllayer::SinglePlayer

A SinglePlayer takes care of playing a single track, and controlling the playback with commands like pause, resume, seek, and so on. It probably starts an external audio player process to do this job. This class is an interface that is to be implemented for different audio players. Then the user can choose which SinglePlayer to use based on what audio players they have installed.

All methods that perform an action should return false if the action isn’t applicable, and return a truthy value otherwise.

Public Instance Methods

mute() click to toggle source

Mute the audio player.

# File lib/plllayer/single_player.rb, line 88
def mute
  raise NotImplementedError
end
muted?() click to toggle source

Return true if audio is muted.

# File lib/plllayer/single_player.rb, line 83
def muted?
  raise NotImplementedError
end
pause() click to toggle source

Pause playback.

# File lib/plllayer/single_player.rb, line 43
def pause
  raise NotImplementedError
end
play(track_path, &on_end) click to toggle source

Begin playing a track. The track_path should be a String representing a path to an audio file. The &on_end callback should be called when the track is finished playing. Should raise FileNotFoundError if the audio file doesn’t exist.

# File lib/plllayer/single_player.rb, line 33
def play(track_path, &on_end)
  raise NotImplementedError
end
playing?() click to toggle source

Return true if a track is currently loaded, i.e. either playing or paused.

# File lib/plllayer/single_player.rb, line 20
def playing?
  raise NotImplementedError
end
position() click to toggle source

Return the current time into the song, in milliseconds.

# File lib/plllayer/single_player.rb, line 108
def position
  raise NotImplementedError
end
resume() click to toggle source

Resume playback.

# File lib/plllayer/single_player.rb, line 48
def resume
  raise NotImplementedError
end
seek(where, type = :absolute) click to toggle source

Seek to a particular position in the track. Different types can be supported, such as absolute, relative, or percent. All times are specified in milliseconds. A NotImplementedError should be raised when a certain type isn’t supported.

# File lib/plllayer/single_player.rb, line 56
def seek(where, type = :absolute)
  case type
  when :absolute
    raise NotImplementedError
  when :relative
    raise NotImplementedError
  when :percent
    raise NotImplementedError
  else
    raise NotImplementedError
  end
end
speed() click to toggle source

Get the current playback speed. The speed is a multiplier. For example, double speed is 2 and half-speed is 0.5. Normal speed is 1.

# File lib/plllayer/single_player.rb, line 71
def speed
  raise NotImplementedError
end
speed=(new_speed) click to toggle source

Set the playback speed. The speed is a multiplier. For example, for double speed you’d set it to 2 and for half-speed you’d set it to 0.5. And for normal speed: 1.

# File lib/plllayer/single_player.rb, line 78
def speed=(new_speed)
  raise NotImplementedError
end
stop() click to toggle source

Stop playback.

# File lib/plllayer/single_player.rb, line 38
def stop
  raise NotImplementedError
end
track_length() click to toggle source

Return the length of the current track, in milliseconds.

# File lib/plllayer/single_player.rb, line 113
def track_length
  raise NotImplementedError
end
track_path() click to toggle source

Get the current track path which was passed to the play method.

# File lib/plllayer/single_player.rb, line 25
def track_path
  raise NotImplementedError
end
unmute() click to toggle source

Unmute the audio player.

# File lib/plllayer/single_player.rb, line 93
def unmute
  raise NotImplementedError
end
volume() click to toggle source

Get the current volume as a percentage.

# File lib/plllayer/single_player.rb, line 98
def volume
  raise NotImplementedError
end
volume=(new_volume) click to toggle source

Set the volume as a percentage. The player may be automatically unmuted.

# File lib/plllayer/single_player.rb, line 103
def volume=(new_volume)
  raise NotImplementedError
end