class Rabbit::VideoWindow
Public Class Methods
new(window)
click to toggle source
# File lib/rabbit/video-window.rb, line 37 def initialize(window) @parent_window = window init_window init_keys end
show(window, element)
click to toggle source
# File lib/rabbit/video-window.rb, line 27 def show(window, element) @instance ||= VideoWindow.new(window) @instance.show(element) end
unset_instance()
click to toggle source
# File lib/rabbit/video-window.rb, line 32 def unset_instance @instance = nil end
Public Instance Methods
show(element)
click to toggle source
# File lib/rabbit/video-window.rb, line 43 def show(element) @player.filename = element.filename @window.resize(element.width, element.height) @window.show_all @player.playing = true end
Private Instance Methods
init_keys()
click to toggle source
# File lib/rabbit/video-window.rb, line 86 def init_keys @window.signal_connect(:key_press_event) do |widget, key| case key.keyval when Gdk::Keyval::KEY_space @player.playing = !@player.playing? when Gdk::Keyval::KEY_plus seek(10) when Gdk::Keyval::KEY_minus seek(-10) when *[ Keys::MOVE_TO_NEXT_KEYS, Keys::MOVE_TO_PREVIOUS_KEYS, Keys::MOVE_TO_LAST_KEYS, Keys::MOVE_TO_LAST_KEYS, ].flatten @window.destroy Gtk::AccelGroup.activate(@parent_window, key.keyval, key.state) else Gtk::AccelGroup.activate(@parent_window, key.keyval, key.state) end true end end
init_window()
click to toggle source
# File lib/rabbit/video-window.rb, line 51 def init_window @window = Gtk::ApplicationWindow.new(Rabbit.application) @window.modal = true @window.set_transient_for(@parent_window) @embed = ClutterGtk::Embed.new @window.add(@embed) @stage = @embed.stage @player = ClutterGst::Playback.new @player.seek_flags = :accurate @player.signal_connect(:eos) do @player.progress = 0.0 @player.playing = true end @aspect_ratio = ClutterGst::Aspectratio.new @aspect_ratio.player = @player @video = Clutter::Actor.new @video.width = @stage.width @video.height = @stage.height @video.content = @aspect_ratio @stage.add_child(@video) @window.signal_connect(:button_press_event) do |widget, event| @player.playing = !@player.playing? end @window.signal_connect(:destroy) do @player.playing = false self.class.unset_instance end end
seek(second)
click to toggle source
# File lib/rabbit/video-window.rb, line 108 def seek(second) duration = @player.duration progress = @player.progress + (second / duration) if progress < 0.0 progress = 0.0 elsif progress > 1.0 progress = 1.0 end @player.progress = progress end