Module: VLC::Client::MediaControls
- Included in:
- VLC::Client
- Defined in:
- lib/vlc-client/client/media_controls.rb
Constant Summary collapse
- STATUS_MAPPING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Expressions for parsing VLC's "status" command
{ file: /\( new input: file:\/\/(.*) \)/, volume: /\( audio volume: (\d+) \)/, state: /\( state (.*) \)/ , }.freeze
Instance Method Summary collapse
-
#length ⇒ Integer
Gets the length of the media being played.
-
#pause ⇒ Object
Pauses playback.
-
#play(media = nil) ⇒ Object
Plays media or resumes playback.
-
#playing? ⇒ Boolean
Queries VLC if media is being played.
-
#progress ⇒ Integer
Get the progress of the the media being played.
-
#seek(seconds = 0) ⇒ Object
Seek in seconds.
-
#status ⇒ Hash{Symbol => String}
The mapping of status strings.
-
#stop ⇒ Object
Stops media currently playing.
-
#stopped? ⇒ Boolean
Queries VLC if playback is currently stopped.
-
#time ⇒ Integer
Gets the current playback progress in time.
-
#title ⇒ Object
Gets the title of the media at play.
-
#volume(level = nil) ⇒ Object
Queries/Sets VLC volume level.
- #volume=(level) ⇒ Object
Instance Method Details
#length ⇒ Integer
Gets the length of the media being played
70 71 72 73 74 |
# File 'lib/vlc-client/client/media_controls.rb', line 70 def length Integer(connection.write("get_length", false)) rescue ArgumentError 0 end |
#pause ⇒ Object
Pauses playback
37 38 39 |
# File 'lib/vlc-client/client/media_controls.rb', line 37 def pause connection.write("pause") end |
#play(media) ⇒ Object #play ⇒ Object
Plays media or resumes playback
32 33 34 |
# File 'lib/vlc-client/client/media_controls.rb', line 32 def play(media = nil) connection.write(media.nil? ? "play" : "add #{media(media)}") end |
#playing? ⇒ Boolean
Queries VLC if media is being played
86 87 88 |
# File 'lib/vlc-client/client/media_controls.rb', line 86 def connection.write("is_playing", false) == "1" end |
#progress ⇒ Integer
Get the progress of the the media being played
80 81 82 83 |
# File 'lib/vlc-client/client/media_controls.rb', line 80 def progress l = length l.zero? ? 0 : 100 * time / l end |
#seek(seconds = 0) ⇒ Object
Seek in seconds
42 43 44 |
# File 'lib/vlc-client/client/media_controls.rb', line 42 def seek(seconds = 0) connection.write("seek #{seconds.to_i}") end |
#status ⇒ Hash{Symbol => String}
Returns the mapping of status strings.
123 124 125 126 127 128 129 130 |
# File 'lib/vlc-client/client/media_controls.rb', line 123 def status connection.write("status") raw_status = 3.times.collect { connection.read } STATUS_MAPPING.keys.zip(raw_status).map do |k, s| [k, STATUS_MAPPING[k].match(s)[1]] end.to_h end |
#stop ⇒ Object
Stops media currently playing
47 48 49 |
# File 'lib/vlc-client/client/media_controls.rb', line 47 def stop connection.write("stop") end |
#stopped? ⇒ Boolean
Queries VLC if playback is currently stopped
91 92 93 |
# File 'lib/vlc-client/client/media_controls.rb', line 91 def stopped? connection.write("is_playing", false) == "0" end |
#time ⇒ Integer
Gets the current playback progress in time
60 61 62 63 64 |
# File 'lib/vlc-client/client/media_controls.rb', line 60 def time Integer(connection.write("get_time", false)) rescue ArgumentError 0 end |
#title ⇒ Object
Gets the title of the media at play
52 53 54 |
# File 'lib/vlc-client/client/media_controls.rb', line 52 def title connection.write("get_title", false) end |
#volume ⇒ Integer #volume(level) ⇒ Object
Queries/Sets VLC volume level
105 106 107 108 109 110 |
# File 'lib/vlc-client/client/media_controls.rb', line 105 def volume(level = nil) return Integer(connection.write("volume", false)) if level.nil? connection.write("volume #{Integer(level)}") rescue ArgumentError level.nil? ? 0 : nil end |
#volume=(level) ⇒ Object
113 114 115 |
# File 'lib/vlc-client/client/media_controls.rb', line 113 def volume=(level) volume(level) end |