Skip to content

Commit bef845f

Browse files
author
Aaron Gotwalt
committed
Preserve volume and mute status
1 parent 6e00aa2 commit bef845f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

lib/ghosty/ghost.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ def initialize(speaker, track)
1919
def save_state
2020
puts 'Saving speaker state'
2121
speaker.pause if @was_playing = playing?
22+
speaker.unmute if @was_muted = speaker.muted?
23+
@previous_volume = speaker.volume
2224
@previous = speaker.now_playing
2325
end
2426

2527
def play(track)
2628
puts "Playing track #{track} on speaker #{speaker.name}"
2729

30+
speaker.volume = rand(15)
31+
2832
# queue up the track
2933
speaker.play track
3034

@@ -43,6 +47,9 @@ def restore_state
4347
if @previous
4448
speaker.select_track @previous[:queue_position]
4549
speaker.seek Time.parse("1/1/1970 #{@previous[:current_position]} -0000" ).to_i
50+
51+
speaker.volume = @previous_volume
52+
speaker.mute if @was_muted
4653
end
4754

4855
speaker.play if @was_playing

0 commit comments

Comments
 (0)