#!/usr/bin/env ruby # # This sample code is a port of clutter-gst/examples/video-player.c. The # image files used in this sample code are copied from clutter-gst/examples. # They are licensed under the terms of the GNU Lesser General Public # License, version 2.1 or (at your option) later. # # The original header: # video-player.c - A simple video player with an OSD. # # Copyright (C) 2007,2008 OpenedHand # Copyright (C) 2013 Collabora # # Copyright (C) 2013-2014 Ruby-GNOME2 Project Team # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require "optparse" require "clutter-gst" SEEK_H = 14 SEEK_W = 440 GST_PLAY_FLAG_VIS = (1 << 3) class VideoApp attr_accessor :stage attr_accessor :vtexture attr_accessor :control, :control_bg, :control_label attr_accessor :control_play, :control_pause attr_accessor :control_seek1, :control_seek2, :control_seekbar attr_accessor :controls_showing, :paused, :mouse_in_window attr_accessor :controls_timeout def initialize @controls_showing = false @paused = false @mouse_in_window = false @controls_timeout = 0 end end opt_fullscreen = false opt_loop = false parser = OptionParser.new parser.on("-f", "--[no-]fullscreen", "Start the player in fullscreen", "(#{opt_fullscreen})") do |boolean| opt_fullscreen = boolean end parser.on("-l", "--[no-]loop", "Start the video again once reached EOS", "(#{opt_loop})") do |boolean| opt_loop = boolean end parser.parse! def controls_timeout_cb(app) app.controls_timeout = 0 show_controls(app, false) false end def actor_animate(actor, mode, duration, first_property, *args) actor.save_easing_state actor.easing_mode = mode actor.easing_duration = duration actor.set_property(first_property, args.first) end def show_controls(app, vis) return if app.control.nil? if vis == true && app.controls_showing == true if app.controls_timeout == 0 app.controls_timeout = GLib::Timeout.add_seconds(5) do controls_timeout_cb(app) end end return end if vis == true && app.controls_showing == false app.controls_showing = true app.stage.show_cursor actor_animate(app.control, :ease_out_quint, 250, "opacity", 224) return end if vis == false && app.controls_showing == true app.controls_showing = false if app.mouse_in_window app.stage.hide_cursor end actor_animate(app.control, :ease_out_quint, 250, "opacity", 0) return end end def toggle_pause_state(app) return if app.vtexture.nil? if app.paused app.vtexture.playing = true app.paused = false app.control_play.hide app.control_pause.show else app.vtexture.playing = false app.paused = true app.control_pause.hide app.control_play.show end end def position_controls(app, controls) stage_width, stage_height = app.stage.size bg_width, bg_height = app.control.size x = ((stage_width - bg_width) / 2).floor y = stage_height - bg_height - 28 controls.set_position(x, y) end def new_rectangle_with_color(color) actor = Clutter::Actor.new actor.background_color = color actor end stage_color = Clutter::Color.new(0, 0, 0, 0) control_color1 = Clutter::Color.new(73, 74, 77, 0xee) control_color2 = Clutter::Color.new(0xcc, 0xcc, 0xcc, 0xff) if ARGV.length < 1 puts "Usage: #{$0} [OPTIONS]