Guest User

Untitled

a guest
Apr 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.89 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.         ((XOverlay) sink).set_xwindow_id (Gdk.X11Window.get_xid (drawing_area.get_window ()));
  35.         playbin.set_state (State.PLAYING);
  36.     }
  37.    
  38.     public void on_pause()
  39.     {
  40.         playbin.set_state (State.PAUSED);
  41.     }
  42.    
  43.     public void on_open()
  44.     {
  45.         var file_chooser = new FileChooserDialog("Select media", this, FileChooserAction.OPEN, Stock.CANCEL, ResponseType.CANCEL, Stock.OPEN, ResponseType.ACCEPT, null);
  46.         if (file_chooser.run() == ResponseType.ACCEPT)
  47.         {
  48.             playbin.set_state(State.READY);
  49.             playbin.uri = file_chooser.get_uri();
  50.         }
  51.         file_chooser.destroy();
  52.     }
  53.        
  54. }
  55.  
  56. public static int main(string[] args)
  57. {
  58.     Gtk.init(ref args);
  59.     Gst.init(ref args);
  60.     var app = new player_window();
  61.     app.show_all();
  62.     Gtk.main();
  63.     return 0;
  64. }
Add Comment
Please, Sign In to add comment