Class: Caldera::Player

Inherits:
Object
  • Object
show all
Includes:
EventEmitter
Defined in:
lib/caldera/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guild_id, node, client) ⇒ Player



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/caldera/player.rb', line 40

def initialize(guild_id, node, client)
  @guild_id = guild_id
  @node = node
  @client = client
  @volume = 100
  @paused = false
  @position = 0
  @time = 0

  register_node_handlers
end

Instance Attribute Details

#clientClient (readonly)



22
23
24
# File 'lib/caldera/player.rb', line 22

def client
  @client
end

#guild_idString (readonly)



16
17
18
# File 'lib/caldera/player.rb', line 16

def guild_id
  @guild_id
end

#nodeNode (readonly)



19
20
21
# File 'lib/caldera/player.rb', line 19

def node
  @node
end

#pausedtrue, false (readonly)



28
29
30
# File 'lib/caldera/player.rb', line 28

def paused
  @paused
end

#positionInteger (readonly)



31
32
33
# File 'lib/caldera/player.rb', line 31

def position
  @position
end

#timeTime (readonly)



34
35
36
# File 'lib/caldera/player.rb', line 34

def time
  @time
end

#trackTrack (readonly) Also known as: now_playing



37
38
39
# File 'lib/caldera/player.rb', line 37

def track
  @track
end

#volume(level) ⇒ Object (readonly)

Set the volume of the player



25
26
27
# File 'lib/caldera/player.rb', line 25

def volume
  @volume
end

Instance Method Details

#destroyObject

Destroy this player



110
111
112
# File 'lib/caldera/player.rb', line 110

def destroy
  send_packet(:destroy)
end

#equalizer(**bands) ⇒ Object

Adjust the gain of bands.

Examples:

player.equalizer(1 => 0.25, 5 => -0.25, 10 => 0.0)


101
102
103
104
105
106
107
# File 'lib/caldera/player.rb', line 101

def equalizer(**bands)
  send_packet(:equalizer, {
    bands: bands.collect do |band,gain| 
      { band: band.to_i, gain: gain.to_f }
    end
  })
end

#load_tracksObject

See Node#load_tracks



121
122
123
# File 'lib/caldera/player.rb', line 121

def load_tracks(...)
  @node.load_tracks(...)
end

#pauseObject

Pause playback.



69
70
71
72
73
# File 'lib/caldera/player.rb', line 69

def pause
  send_packet(:pause, {
    pause: true
  })
end

#play(track, start_time: 0, end_time: 0) ⇒ Object

Play a track.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/caldera/player.rb', line 56

def play(track, start_time: 0, end_time: 0)      
  @paused = false
  @track = track
  
  send_packet(:play, {
     track: track.is_a?(Model::Track) ? track.track_data : track,
     startTime: start_time,
     endTime: end_time,
     noReplace: false
  })
end

#seek(position) ⇒ Object

Seek to a position in the track.



84
85
86
87
88
# File 'lib/caldera/player.rb', line 84

def seek(position)
  send_packet(:seek, {
    position: position
  })
end

#unpauseObject

Resume the player.



76
77
78
79
80
# File 'lib/caldera/player.rb', line 76

def unpause
  send_packet(:pause, {
    pause: false
  })
end