Class: Plllayer::SinglePlayer
- Inherits:
-
Object
- Object
- Plllayer::SinglePlayer
- 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.
Direct Known Subclasses
Plllayer::SinglePlayers::MPlayer, Plllayer::SinglePlayers::Nop
Instance Method Summary collapse
-
#mute ⇒ Object
Mute the audio player.
-
#muted? ⇒ Boolean
Return true if audio is muted.
-
#pause ⇒ Object
Pause playback.
-
#play(track_path, &on_end) ⇒ Object
Begin playing a track.
-
#playing? ⇒ Boolean
Return true if a track is currently loaded, i.e.
-
#position ⇒ Object
Return the current time into the song, in milliseconds.
-
#resume ⇒ Object
Resume playback.
-
#seek(where, type = :absolute) ⇒ Object
Seek to a particular position in the track.
-
#speed ⇒ Object
Get the current playback speed.
-
#speed=(new_speed) ⇒ Object
Set the playback speed.
-
#stop ⇒ Object
Stop playback.
-
#track_length ⇒ Object
Return the length of the current track, in milliseconds.
-
#track_path ⇒ Object
Get the current track path which was passed to the play method.
-
#unmute ⇒ Object
Unmute the audio player.
-
#volume ⇒ Object
Get the current volume as a percentage.
-
#volume=(new_volume) ⇒ Object
Set the volume as a percentage.
Instance Method Details
#mute ⇒ Object
Mute the audio player.
88 89 90 |
# File 'lib/plllayer/single_player.rb', line 88 def mute raise NotImplementedError end |
#muted? ⇒ Boolean
Return true if audio is muted.
83 84 85 |
# File 'lib/plllayer/single_player.rb', line 83 def muted? raise NotImplementedError end |
#pause ⇒ Object
Pause playback.
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.
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.
20 21 22 |
# File 'lib/plllayer/single_player.rb', line 20 def raise NotImplementedError end |
#position ⇒ Object
Return the current time into the song, in milliseconds.
108 109 110 |
# File 'lib/plllayer/single_player.rb', line 108 def position raise NotImplementedError end |
#resume ⇒ Object
Resume playback.
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 |
#speed ⇒ Object
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.
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.
78 79 80 |
# File 'lib/plllayer/single_player.rb', line 78 def speed=(new_speed) raise NotImplementedError end |
#stop ⇒ Object
Stop playback.
38 39 40 |
# File 'lib/plllayer/single_player.rb', line 38 def stop raise NotImplementedError end |
#track_length ⇒ Object
Return the length of the current track, in milliseconds.
113 114 115 |
# File 'lib/plllayer/single_player.rb', line 113 def track_length raise NotImplementedError end |
#track_path ⇒ Object
Get the current track path which was passed to the play method.
25 26 27 |
# File 'lib/plllayer/single_player.rb', line 25 def track_path raise NotImplementedError end |
#unmute ⇒ Object
Unmute the audio player.
93 94 95 |
# File 'lib/plllayer/single_player.rb', line 93 def unmute raise NotImplementedError end |
#volume ⇒ Object
Get the current volume as a percentage.
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.
103 104 105 |
# File 'lib/plllayer/single_player.rb', line 103 def volume=(new_volume) raise NotImplementedError end |