Guest User

Untitled

a guest
Apr 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.93 KB | None | 0 0
  1. using Gtk;
  2. using Gst;
  3.  
  4. public class player_window : Window
  5. {
  6.     private ToolButton open_button = new ToolButton.from_stock (Stock.OPEN);
  7.     private ToolButton play_button = new ToolButton.from_stock (Stock.MEDIA_PLAY);
  8.     private ToolButton pause_button = new ToolButton.from_stock (Stock.MEDIA_PAUSE);
  9.     private DrawingArea drawing_area = new DrawingArea();
  10.     private Box vbox = new Box(Orientation.VERTICAL, 4);
  11.     private Box hbox = new Box(Orientation.HORIZONTAL, 2);
  12.     dynamic Element playbin = ElementFactory.make ("playbin2", "playbin");
  13.     Element sink = ElementFactory.make ("xvimagesink", "sink");
  14.    
  15.     public player_window()
  16.     {
  17.         title = "My Fiwst Pwogwam";
  18.         hbox.pack_start(play_button, true, true, 0);
  19.         hbox.pack_start(pause_button, true, true, 0);
  20.         drawing_area.set_size_request(320, 240);
  21.         vbox.pack_start(drawing_area, true, true, 0);
  22.         vbox.pack_start(open_button, true, true, 0);
  23.         vbox.pack_start(hbox, true, true, 0);
  24.         add(vbox);
  25.         play_button.clicked.connect(on_play);
  26.         pause_button.clicked.connect(on_pause);
  27.         open_button.clicked.connect(on_open);
  28.         destroy.connect (Gtk.main_quit);
  29.     }
  30.    
  31.     public void on_play()
  32.     {
  33.         playbin.video_sink = sink;
  34.         sink.set("force-aspect-ratio", true);
  35.         ((XOverlay) sink).set_xwindow_id (Gdk.X11Window.get_xid (drawing_area.get_window ()));
  36.         playbin.set_state (State.PLAYING);
  37.     }
  38.    
  39.     public void on_pause()
  40.     {
  41.         playbin.set_state (State.PAUSED);
  42.     }
  43.    
  44.     public void on_open()
  45.     {
  46.         var file_chooser = new FileChooserDialog("Select media", this, FileChooserAction.OPEN, Stock.CANCEL, ResponseType.CANCEL, Stock.OPEN, ResponseType.ACCEPT, null);
  47.         if (file_chooser.run() == ResponseType.ACCEPT)
  48.         {
  49.             playbin.set_state(State.READY);
  50.             playbin.uri = file_chooser.get_uri();
  51.         }
  52.         file_chooser.destroy();
  53.     }
  54.        
  55. }
  56.  
  57. public static int main(string[] args)
  58. {
  59.     Gtk.init(ref args);
  60.     Gst.init(ref args);
  61.     var app = new player_window();
  62.     app.show_all();
  63.     Gtk.main();
  64.     return 0;
  65. }
Add Comment
Please, Sign In to add comment