Class: Plllayer::SinglePlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/plllayer/single_player.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#muteObject

Mute the audio player.

Raises:

  • (NotImplementedError)


88
89
90
# File 'lib/plllayer/single_player.rb', line 88

def mute
  raise NotImplementedError
end

#muted?Boolean

Return true if audio is muted.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def muted?
  raise NotImplementedError
end

#pauseObject

Pause playback.

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/plllayer/single_player.rb', line 43

def pause
  raise NotImplementedError
end

#play(track_path, &on_end) ⇒ Object

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.

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/plllayer/single_player.rb', line 33

def play(track_path, &on_end)
  raise NotImplementedError
end

#playing?Boolean

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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/plllayer/single_player.rb', line 20

def playing?
  raise NotImplementedError
end

#positionObject

Return the current time into the song, in milliseconds.

Raises:

  • (NotImplementedError)


108
109
110
# File 'lib/plllayer/single_player.rb', line 108

def position
  raise NotImplementedError
end

#resumeObject

Resume playback.

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/plllayer/single_player.rb', line 48

def resume
  raise NotImplementedError
end

#seek(where, type = :absolute) ⇒ Object

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.



56
57
58
59
60
61
62
63
64
65
66
67
# 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

#speedObject

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.

Raises:

  • (NotImplementedError)


71
72
73
# File 'lib/plllayer/single_player.rb', line 71

def speed
  raise NotImplementedError
end

#speed=(new_speed) ⇒ Object

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.

Raises:

  • (NotImplementedError)


78
79
80
# File 'lib/plllayer/single_player.rb', line 78

def speed=(new_speed)
  raise NotImplementedError
end

#stopObject

Stop playback.

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/plllayer/single_player.rb', line 38

def stop
  raise NotImplementedError
end

#track_lengthObject

Return the length of the current track, in milliseconds.

Raises:

  • (NotImplementedError)


113
114
115
# File 'lib/plllayer/single_player.rb', line 113

def track_length
  raise NotImplementedError
end

#track_pathObject

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

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/plllayer/single_player.rb', line 25

def track_path
  raise NotImplementedError
end

#unmuteObject

Unmute the audio player.

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/plllayer/single_player.rb', line 93

def unmute
  raise NotImplementedError
end

#volumeObject

Get the current volume as a percentage.

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/plllayer/single_player.rb', line 98

def volume
  raise NotImplementedError
end

#volume=(new_volume) ⇒ Object

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

Raises:

  • (NotImplementedError)


103
104
105
# File 'lib/plllayer/single_player.rb', line 103

def volume=(new_volume)
  raise NotImplementedError
end