Class: Caldera::Player
- Inherits:
-
Object
- Object
- Caldera::Player
- Includes:
- EventEmitter
- Defined in:
- lib/caldera/player.rb
Instance Attribute Summary collapse
- #client ⇒ Client readonly
- #guild_id ⇒ String readonly
-
#node ⇒ Node
readonly
The node that owns this player.
- #paused ⇒ true, false readonly
- #position ⇒ Integer readonly
- #time ⇒ Time readonly
- #track ⇒ Track (also: #now_playing) readonly
-
#volume(level) ⇒ Object
readonly
Set the volume of the player.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy this player.
-
#equalizer(**bands) ⇒ Object
Adjust the gain of bands.
-
#initialize(guild_id, node, client) ⇒ Player
constructor
A new instance of Player.
-
#load_tracks ⇒ Object
See Node#load_tracks.
-
#pause ⇒ Object
Pause playback.
-
#play(track, start_time: 0, end_time: 0) ⇒ Object
Play a track.
-
#seek(position) ⇒ Object
Seek to a position in the track.
-
#unpause ⇒ Object
Resume the player.
Constructor Details
#initialize(guild_id, node, client) ⇒ Player
Returns a new instance of 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
#guild_id ⇒ String (readonly)
16 17 18 |
# File 'lib/caldera/player.rb', line 16 def guild_id @guild_id end |
#node ⇒ Node (readonly)
Returns The node that owns this player.
19 20 21 |
# File 'lib/caldera/player.rb', line 19 def node @node end |
#paused ⇒ true, false (readonly)
28 29 30 |
# File 'lib/caldera/player.rb', line 28 def paused @paused end |
#position ⇒ Integer (readonly)
31 32 33 |
# File 'lib/caldera/player.rb', line 31 def position @position end |
#time ⇒ Time (readonly)
34 35 36 |
# File 'lib/caldera/player.rb', line 34 def time @time end |
#track ⇒ Track (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
#destroy ⇒ Object
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.
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_tracks ⇒ Object
See Node#load_tracks
121 122 123 |
# File 'lib/caldera/player.rb', line 121 def load_tracks(...) @node.load_tracks(...) end |
#pause ⇒ Object
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 |
#unpause ⇒ Object
Resume the player.
76 77 78 79 80 |
# File 'lib/caldera/player.rb', line 76 def unpause send_packet(:pause, { pause: false }) end |