Class: Muzak::Player::VLC

Inherits:
StubPlayer show all
Defined in:
lib/muzak/player/vlc.rb

Overview

Exposes a VLC process to muzak for playback control.

Instance Attribute Summary

Attributes inherited from StubPlayer

#instance

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StubPlayer

#initialize, player_name, #shuffle_queue

Methods included from Utils

album_art?, #build_response, #danger, #debug, #debug?, #error, #error!, music?, #output, #pretty, #verbose, #verbose?, which?

Constructor Details

This class inherits a constructor from Muzak::Player::StubPlayer

Class Method Details

.available?Boolean

Returns whether or not VLC is available.

Returns:

  • (Boolean)

    whether or not VLC is available



10
11
12
# File 'lib/muzak/player/vlc.rb', line 10

def self.available?
  Utils.which?("vlc") && Utils.which?("cvlc")
end

Instance Method Details

#activate!void

This method returns an undefined value.

Activates a VLC process.



21
22
23
24
25
26
27
28
29
# File 'lib/muzak/player/vlc.rb', line 21

def activate!
  return if running?

  debug "activating #{self.class}"

  @vlc = ::VLC::System.new

  instance.event :player_activated
end

#clear_queuevoid

This method returns an undefined value.

Clear VLC's internal queue.



137
138
139
140
# File 'lib/muzak/player/vlc.rb', line 137

def clear_queue
  return unless running?
  @vlc.clear
end

#deactivate!void

This method returns an undefined value.

Deactivates the VLC process, if one is running.



33
34
35
36
37
38
39
40
41
42
# File 'lib/muzak/player/vlc.rb', line 33

def deactivate!
  return unless running?

  debug "deactivating #{self.class}"

  @vlc.client.disconnect
  @vlc.server.stop

  instance.event :player_deactivated
end

#enqueue_album(album) ⇒ void

Note:

Activates VLC if not already activated.

This method returns an undefined value.

Tell VLC to add the given album to its queue.

Parameters:

  • album (Album)

    the album to add



97
98
99
100
101
102
103
# File 'lib/muzak/player/vlc.rb', line 97

def enqueue_album(album)
  activate! unless running?

  album.songs.each do |song|
    load_song song
  end
end

#enqueue_playlist(playlist) ⇒ void

Note:

Activates VLC if not already activated.

This method returns an undefined value.

Tell VLC to add the given playlist to its queue.

Parameters:

  • playlist (Playlist)

    the playlist to add



109
110
111
112
113
114
115
# File 'lib/muzak/player/vlc.rb', line 109

def enqueue_playlist(playlist)
  activate! unless running?

  playlist.songs.each do |song|
    load_song song
  end
end

#enqueue_song(song) ⇒ void

Note:

Activates VLC if not already activated.

This method returns an undefined value.

Tell VLC to add the given song to its queue.

Parameters:

  • song (Song)

    the song to add



87
88
89
90
91
# File 'lib/muzak/player/vlc.rb', line 87

def enqueue_song(song)
  activate! unless running?

  load_song song
end

#list_queueArray<Song>

TODO:

Implement this.

Note:

This includes songs already played.

Get VLC's internal queue.

Returns:

  • (Array<Song>)

    all songs in VLC's queue



121
122
123
124
125
126
# File 'lib/muzak/player/vlc.rb', line 121

def list_queue
  debug @vlc.playlist.to_s
  danger "this player doesn't support list_queue"
  # TODO: figure out how to get VLC::Client#playlist to return filenames
  []
end

#load_song(song) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Load a song into VLC.

Parameters:

  • song (Song)

    the song to load



154
155
156
157
# File 'lib/muzak/player/vlc.rb', line 154

def load_song(song)
  @vlc.add_to_playlist song.path
  @vlc.play if Config.autoplay
end

#next_songvoid

Note:

Does nothing if the current song is the last.

This method returns an undefined value.

Tell VLC to play the next song in its queue.



72
73
74
# File 'lib/muzak/player/vlc.rb', line 72

def next_song
  @vlc.next
end

#now_playingSong?

Get VLC's currently loaded song.

Returns:

  • (Song, nil)

    the currently loaded song



144
145
146
147
148
# File 'lib/muzak/player/vlc.rb', line 144

def now_playing
  return unless playing?

  Song.new(@vlc.status[:file])
end

#pausevoid

Note:

Does nothing is playback is already paused.

This method returns an undefined value.

Tell VLC to pause playback.



56
57
58
59
60
# File 'lib/muzak/player/vlc.rb', line 56

def pause
  return unless running?

  @vlc.pause
end

#playvoid

Note:

Does nothing is playback is already in progress.

This method returns an undefined value.

Tell VLC to begin playback.



47
48
49
50
51
# File 'lib/muzak/player/vlc.rb', line 47

def play
  return unless running?

  @vlc.play
end

#playing?Boolean

Returns whether or not VLC is currently playing.

Returns:

  • (Boolean)

    whether or not VLC is currently playing.



63
64
65
66
67
# File 'lib/muzak/player/vlc.rb', line 63

def playing?
  return false unless running?

  @vlc.playing?
end

#previous_songvoid

Note:

Restarts the song if the current song is the first.

This method returns an undefined value.

Tell VLC to play the previous song in its queue.



79
80
81
# File 'lib/muzak/player/vlc.rb', line 79

def previous_song
  @vlc.previous
end

#running?Boolean

Returns whether or not the current instance is running.

Returns:

  • (Boolean)

    whether or not the current instance is running.



15
16
17
# File 'lib/muzak/player/vlc.rb', line 15

def running?
  !!@vlc&.connected?
end

#shufflevoid

TODO:

Implement this.

This method returns an undefined value.

Shuffle VLC's internal queue.



131
132
133
# File 'lib/muzak/player/vlc.rb', line 131

def shuffle
  danger "this player doesn't support shuffling (?)"
end