class ActiveVlc::LibVlc::EventManager
Constants
- EventType
Attributes
callbacks[R]
events_received[R]
Public Class Methods
new(ptr)
click to toggle source
# File lib/activevlc/libvlc/event_manager.rb, line 12 def initialize(ptr) @ptr = ptr @callbacks = {} @events_received = 0 @event_handler = Proc.new { |event, void| _event(event, void) } end
Public Instance Methods
on(types, &block)
click to toggle source
# File lib/activevlc/libvlc/event_manager.rb, line 20 def on(types, &block) event_is_valid = true types = [types] unless types.is_a? Array # Get the enum value if we gat a Symbol or String types.each do |type| if type.is_a?(String) or type.is_a?(Symbol) type = EventType[type.to_sym] end # If this is the first callback for this type, register the :event_handler # using vlc's API and create the proc array for that 'type'. unless @callbacks[type] event_is_valid = Api.libvlc_event_attach(@ptr, type, @event_handler, nil) == 0 @callbacks[type] = Array.new if event_is_valid end @callbacks[type].push block if event_is_valid end end
Protected Instance Methods
_event(event, void)
click to toggle source
# File lib/activevlc/libvlc/event_manager.rb, line 41 def _event(event, void) event = Event.new(event) type = EventType[event[:type]] @events_received += 1; # puts "Received event (#{@events_received}): #{EventType[event[:type]]}" return unless @callbacks[event[:type]].is_a? Array @callbacks[event[:type]].each { |proc| proc.call(type) } end