Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- using Gst;
- public class Video {
- public string file { get; set; default = ""; }
- public Video (string s) {
- file = s;
- }
- }
- public class Dazzle : dynamic Window {
- private DrawingArea drawing_area;
- Gst.Element visualization;
- private dynamic Element player;
- private Element sink;
- private Gtk.ToolButton play_button;
- private Gtk.ToolButton next_button;
- private Gtk.ToolButton properties_button;
- private HScale slider;
- private ToolItem slider_container;
- private Gtk.Label movie_label;
- private Gtk.Label movie_paused_label;
- private string movie_title;
- private bool isPlaying = false;
- public Dazzle (Video v) {
- create_widgets ();
- setup_gst_pipeline (v);
- }
- private void create_widgets () {
- var vbox = new VBox (false, 0);
- var slider_box = new VBox (false, 0);
- var toolbar = new Toolbar();
- play_button = new ToolButton.from_stock(Stock.MEDIA_PLAY);
- play_button.clicked.connect (on_play);
- properties_button = new ToolButton.from_stock (Stock.PROPERTIES);
- next_button = new ToolButton.from_stock (Stock.MEDIA_NEXT);
- slider = new HScale.with_range (0, 130, 1);
- movie_title = "Title";
- movie_label = new Gtk.Label(movie_title);
- var message = movie_title + " (Paused)";
- movie_paused_label = new Gtk.Label(message);
- movie_paused_label.hide();
- slider_box.pack_start (movie_label);
- slider_box.pack_start (movie_paused_label);
- slider_box.pack_start (slider);
- slider_container = new ToolItem();
- slider_container.add(slider_box);
- slider.set_draw_value(false);
- this.drawing_area = new DrawingArea ();
- this.drawing_area.set_size_request (600, 300);
- slider.set_size_request (drawing_area.width_request - 105, 20);
- toolbar.add (play_button);
- toolbar.add (slider_container);
- toolbar.add (next_button);
- toolbar.add (properties_button);
- vbox.pack_start (toolbar, false, true, 0);
- vbox.pack_start (this.drawing_area, true, true, 0);
- add (vbox);
- show_all();
- movie_paused_label.hide();
- }
- private void setup_gst_pipeline (Video v) {
- sink = Gst.ElementFactory.make ("xvimagesink", "sink");
- sink.set("force-aspect-ratio", true);
- visualization = Gst.ElementFactory.make ("goom2k1", "visualization");
- player = Gst.ElementFactory.make ("playbin", "player");
- player.video_sink = sink;
- player.vis_plugin = visualization;
- player.set_state (Gst.State.NULL);
- player.uri = "file://" + v.file;
- player.set_state (Gst.State.READY);
- player.set_state (Gst.State.PLAYING);
- }
- private void on_play () {
- var xoverlay = sink as XOverlay;
- xoverlay.set_xwindow_id (Gdk.x11_drawable_get_xid (this.drawing_area.window));
- if (isPlaying) {
- isPlaying = false;
- play_button.set_stock_id (Stock.MEDIA_PLAY);
- this.player.set_state (State.PAUSED);
- movie_paused_label.show();
- movie_label.hide();
- } else {
- isPlaying = true;
- play_button.set_stock_id (Stock.MEDIA_PAUSE);
- this.player.set_state (State.PLAYING);
- movie_paused_label.hide();
- movie_label.show();
- }
- }
- public static int main (string[] args) {
- if (args.length != 2) {
- stdout.printf("Error: you must enter an arg like that:\n./Dazzle </ENTIRE/PATH/TO/THE/FILE>\n");
- return 1;
- } else {
- Gst.init (ref args);
- Gtk.init (ref args);
- Video v = new Video(args[1]);
- var sample = new Dazzle (v);
- sample.title = "Dazzle";
- sample.position = WindowPosition.CENTER;
- sample.destroy.connect (Gtk.main_quit);
- Gtk.main ();
- Gtk.main_quit();
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement