lib/kikeru/window.rb in kikeru-0.0.1 vs lib/kikeru/window.rb in kikeru-0.0.2
- old
+ new
@@ -11,42 +11,44 @@
def add_container(container)
@container = container
@file = @container.shift
end
- def play
- @playbin.stop
+ def load
+ stop
@playbin.uri = Gst.filename_to_uri(@file)
self.title = File.basename(@file)
- @playbin.play
+ play
end
private
def setup
setup_window
setup_gst
end
def setup_window
signal_connect("destroy") do
- @playbin.stop
+ stop
Gtk.main_quit
end
signal_connect("key_press_event") do |widget, event|
case event.keyval
when Gdk::Keyval::GDK_KEY_n
@file = @container.shift(@file)
- play
+ load
when Gdk::Keyval::GDK_KEY_p
@file = @container.pop(@file)
- play
+ load
when Gdk::Keyval::GDK_KEY_r
- play
+ load
when Gdk::Keyval::GDK_KEY_q
- @playbin.stop
+ stop
Gtk.main_quit
+ when Gdk::Keyval::GDK_KEY_space
+ toggle
end
end
end
def setup_gst
@@ -55,8 +57,36 @@
@playbin = Gst::ElementFactory.make("playbin")
if @playbin.nil?
puts "'playbin' gstreamer plugin missing"
exit(false)
end
+
+ @playbin.bus.add_watch do |bus, message|
+ case message.type
+ when Gst::MessageType::EOS
+ @file = @container.shift(@file)
+ load
+ end
+ true
+ end
+ end
+
+ def play
+ @playbin.play
+ @playing = true
+ end
+
+ def pause
+ @playbin.pause
+ @playing = false
+ end
+
+ def stop
+ @playbin.stop
+ @playing = false
+ end
+
+ def toggle
+ @playing ? pause : play
end
end
end