Class: Plllayer::SinglePlayers::Nop
- Inherits:
-
Plllayer::SinglePlayer
- Object
- Plllayer::SinglePlayer
- Plllayer::SinglePlayers::Nop
- Defined in:
- lib/plllayer/single_players/nop.rb
Overview
This is the SinglePlayer implentation used for testing. It doesn’t actually do anything, it just pretends to play a music file using sleeps.
Instance Attribute Summary collapse
-
#track_path ⇒ Object
readonly
Returns the value of attribute track_path.
Instance Method Summary collapse
-
#initialize ⇒ Nop
constructor
A new instance of Nop.
- #mute ⇒ Object
- #muted? ⇒ Boolean
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #play(track_path, &on_end) ⇒ Object
- #playing? ⇒ Boolean
- #position ⇒ Object
- #resume ⇒ Object
- #seek(where, type = :absolute) ⇒ Object
- #speed ⇒ Object
- #speed=(new_speed) ⇒ Object
- #stop ⇒ Object
- #track_length ⇒ Object
- #unmute ⇒ Object
- #volume ⇒ Object
- #volume=(new_volume) ⇒ Object
Constructor Details
#initialize ⇒ Nop
Returns a new instance of Nop.
8 9 10 11 12 13 14 |
# File 'lib/plllayer/single_players/nop.rb', line 8 def initialize @paused = false @muted = false @volume = 50 @speed = 1.0 @track_path = nil end |
Instance Attribute Details
#track_path ⇒ Object (readonly)
Returns the value of attribute track_path.
6 7 8 |
# File 'lib/plllayer/single_players/nop.rb', line 6 def track_path @track_path end |
Instance Method Details
#mute ⇒ Object
108 109 110 |
# File 'lib/plllayer/single_players/nop.rb', line 108 def mute @muted = true end |
#muted? ⇒ Boolean
104 105 106 |
# File 'lib/plllayer/single_players/nop.rb', line 104 def muted? @muted end |
#pause ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/plllayer/single_players/nop.rb', line 62 def pause if not @paused and @paused = true else false end end |
#paused? ⇒ Boolean
58 59 60 |
# File 'lib/plllayer/single_players/nop.rb', line 58 def paused? @paused end |
#play(track_path, &on_end) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/plllayer/single_players/nop.rb', line 20 def play(track_path, &on_end) _quit # Make sure the audio file exists. raise FileNotFoundError, "file '#{track_path}' doesn't exist" unless File.exists? track_path @paused = false @track_path = track_path # Assume the filename starts with the song length in milliseconds, so we # don't actually have to read the file. @total_time = File.basename(@track_path, ".*").to_i @time_left = @total_time @last_tick = Time.now @quit_hook_active = false @quit_hook = Thread.new do while @time_left > 0 unless @paused @time_left -= ((Time.now - @last_tick) * 1000 * @speed).to_i end @last_tick = Time.now sleep 0.01 end @quit_hook_active = true @paused = false @track_path = nil @started = nil on_end.call end true end |
#playing? ⇒ Boolean
16 17 18 |
# File 'lib/plllayer/single_players/nop.rb', line 16 def not @track_path.nil? end |
#position ⇒ Object
127 128 129 |
# File 'lib/plllayer/single_players/nop.rb', line 127 def position ? @total_time - @time_left : false end |
#resume ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/plllayer/single_players/nop.rb', line 70 def resume if @paused @paused = false true else false end end |
#seek(where, type = :absolute) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/plllayer/single_players/nop.rb', line 79 def seek(where, type = :absolute) if case type when :absolute @time_left = @total_time - where when :relative @time_left -= where when :percent @time_left = @total_time - (@total_time * where) / 100 end true else false end end |
#speed ⇒ Object
95 96 97 |
# File 'lib/plllayer/single_players/nop.rb', line 95 def speed @speed end |
#speed=(new_speed) ⇒ Object
99 100 101 102 |
# File 'lib/plllayer/single_players/nop.rb', line 99 def speed=(new_speed) @speed = new_speed.to_f true end |
#stop ⇒ Object
54 55 56 |
# File 'lib/plllayer/single_players/nop.rb', line 54 def stop _quit end |
#track_length ⇒ Object
131 132 133 |
# File 'lib/plllayer/single_players/nop.rb', line 131 def track_length ? @total_time : false end |
#unmute ⇒ Object
112 113 114 115 |
# File 'lib/plllayer/single_players/nop.rb', line 112 def unmute @muted = false true end |
#volume ⇒ Object
117 118 119 |
# File 'lib/plllayer/single_players/nop.rb', line 117 def volume @volume end |
#volume=(new_volume) ⇒ Object
121 122 123 124 125 |
# File 'lib/plllayer/single_players/nop.rb', line 121 def volume=(new_volume) @muted = false @volume = new_volume.to_f true end |