Advertisement
maxdudik

Untitled

Oct 8th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 3.80 KB | None | 0 0
  1. using Gtk;
  2. using Gst;
  3.  
  4. public class Video {
  5.     public string file { get; set; default = ""; }
  6.     public Video (string s) {
  7.         file = s;
  8.     }
  9. }
  10.  
  11. public class Dazzle : dynamic Window {
  12.  
  13.     private DrawingArea drawing_area;
  14.  
  15.     Gst.Element visualization;
  16.     private dynamic Element player;
  17.     private Element sink;
  18.  
  19.    
  20.     private Gtk.ToolButton play_button;
  21.     private Gtk.ToolButton next_button;
  22.     private Gtk.ToolButton properties_button;
  23.     private HScale slider;
  24.     private ToolItem slider_container;
  25.     private Gtk.Label movie_label;
  26.     private Gtk.Label movie_paused_label;
  27.     private string movie_title;
  28.     private bool isPlaying = false;
  29.    
  30.     public Dazzle (Video v) {
  31.        
  32.         create_widgets ();
  33.         setup_gst_pipeline (v);
  34.     }
  35.  
  36.     private void create_widgets () {
  37.         var vbox = new VBox (false, 0);
  38.         var slider_box = new VBox (false, 0);
  39.         var toolbar = new Toolbar();
  40.        
  41.         play_button = new ToolButton.from_stock(Stock.MEDIA_PLAY);
  42.         play_button.clicked.connect (on_play);
  43.                
  44.         properties_button = new ToolButton.from_stock (Stock.PROPERTIES);
  45.         next_button = new ToolButton.from_stock (Stock.MEDIA_NEXT);
  46.         slider = new HScale.with_range (0, 130, 1);
  47.        
  48.         movie_title = "Title";
  49.         movie_label = new Gtk.Label(movie_title);
  50.         var message = movie_title + " (Paused)";
  51.         movie_paused_label = new Gtk.Label(message);
  52.         movie_paused_label.hide();
  53.        
  54.         slider_box.pack_start (movie_label);
  55.         slider_box.pack_start (movie_paused_label);
  56.         slider_box.pack_start (slider);
  57.         slider_container = new ToolItem();
  58.         slider_container.add(slider_box);
  59.         slider.set_draw_value(false);
  60.        
  61.         this.drawing_area = new DrawingArea ();
  62.         this.drawing_area.set_size_request (600, 300);
  63.         slider.set_size_request (drawing_area.width_request - 105, 20);
  64.  
  65.         toolbar.add (play_button);
  66.         toolbar.add (slider_container);
  67.         toolbar.add (next_button);
  68.         toolbar.add (properties_button);
  69.        
  70.         vbox.pack_start (toolbar, false, true, 0);
  71.  
  72.         vbox.pack_start (this.drawing_area, true, true, 0);
  73.  
  74.         add (vbox);
  75.         show_all();
  76.         movie_paused_label.hide();
  77.        
  78.        
  79.     }
  80.  
  81.     private void setup_gst_pipeline (Video v) {    
  82.         sink = Gst.ElementFactory.make ("xvimagesink", "sink");
  83.         sink.set("force-aspect-ratio", true);
  84.         visualization = Gst.ElementFactory.make ("goom2k1", "visualization");
  85.         player = Gst.ElementFactory.make ("playbin", "player");
  86.         player.video_sink = sink;
  87.         player.vis_plugin = visualization;
  88.         player.set_state (Gst.State.NULL);
  89.         player.uri = "file://" + v.file;
  90.         player.set_state (Gst.State.READY);
  91.         player.set_state (Gst.State.PLAYING);
  92.     }
  93.  
  94.     private void on_play () {
  95.         var xoverlay = sink as XOverlay;
  96.         xoverlay.set_xwindow_id (Gdk.x11_drawable_get_xid (this.drawing_area.window));
  97.         if (isPlaying) {
  98.             isPlaying = false;
  99.             play_button.set_stock_id (Stock.MEDIA_PLAY);
  100.             this.player.set_state (State.PAUSED);
  101.             movie_paused_label.show();
  102.             movie_label.hide();
  103.         } else {
  104.             isPlaying = true;
  105.             play_button.set_stock_id (Stock.MEDIA_PAUSE);
  106.             this.player.set_state (State.PLAYING);
  107.             movie_paused_label.hide();
  108.             movie_label.show();
  109.         }
  110.     }
  111.  
  112.     public static int main (string[] args) {
  113.         if (args.length != 2) {
  114.             stdout.printf("Error: you must enter an arg like that:\n./Dazzle </ENTIRE/PATH/TO/THE/FILE>\n");
  115.             return 1;
  116.         } else {
  117.             Gst.init (ref args);
  118.             Gtk.init (ref args);
  119.             Video v = new Video(args[1]);        
  120.             var sample = new Dazzle (v);
  121.             sample.title = "Dazzle";
  122.             sample.position = WindowPosition.CENTER;
  123.             sample.destroy.connect (Gtk.main_quit);
  124.                 Gtk.main ();
  125.             Gtk.main_quit();
  126.             return 0;
  127.         }
  128.     }
  129. }
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement