Class: XiamiRadio::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/xiami_radio/player.rb

Overview

There is a player as you saw

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(radio:, _playlist: nil) ⇒ Player

Returns a new instance of Player.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/xiami_radio/player.rb', line 9

def initialize(radio:, _playlist: nil)
  @radio = radio
  @player = Audite.new
  @view = View::Player.new

  @player.events.on :position_change, &method(:position_change)
  @player.events.on :complete, &method(:complete)
  @view.listen_on self

  trap(:SIGUSR1) { self.next }
end

Instance Attribute Details

#next_trackObject (readonly)

Returns the value of attribute next_track.



7
8
9
# File 'lib/xiami_radio/player.rb', line 7

def next_track
  @next_track
end

#radioObject (readonly)

Returns the value of attribute radio.



7
8
9
# File 'lib/xiami_radio/player.rb', line 7

def radio
  @radio
end

#trackObject (readonly)

Returns the value of attribute track.



7
8
9
# File 'lib/xiami_radio/player.rb', line 7

def track
  @track
end

Instance Method Details

#forwardObject



44
45
46
# File 'lib/xiami_radio/player.rb', line 44

def forward
  @player.forward
end

#nextObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/xiami_radio/player.rb', line 29

def next
  @track.downloader.stop
  if preload?
    @track, @next_track = @next_track, nil
  else
    @track = @radio.next_track
    @player.queue @track.file_path
  end
  @player.request_next_song
end

#playObject



21
22
23
24
25
26
27
# File 'lib/xiami_radio/player.rb', line 21

def play
  @track = @radio.next_track
  @player.queue @track.file_path
  @player.set_current_song
  @player.start_stream
  @player.thread.join
end

#rewindObject



40
41
42
# File 'lib/xiami_radio/player.rb', line 40

def rewind
  @player.rewind
end

#toggleObject



48
49
50
# File 'lib/xiami_radio/player.rb', line 48

def toggle
  @player.toggle
end