Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- using Gst;
- public class player_window : Window
- {
- private DrawingArea drawing_area = new DrawingArea();
- private bool state = false;
- private Element sink = ElementFactory.make ("xvimagesink", "sink");
- private dynamic Element playbin = ElementFactory.make("playbin2", "playbin");
- public player_window()
- {
- create_widgets();
- }
- public void create_widgets()
- {
- title = "My Fiwst Pwogwam";
- ToolButton open_button = new ToolButton.from_stock (Stock.OPEN);
- ToolButton play_button = new ToolButton.from_stock (Stock.MEDIA_PLAY);
- ToolButton forward_button = new ToolButton.from_stock (Stock.MEDIA_FORWARD);
- ToolButton rewind_button = new ToolButton.from_stock (Stock.MEDIA_REWIND);
- Box vbox = new Box(Orientation.VERTICAL, 3);
- Box hbox = new Box(Orientation.HORIZONTAL, 2);
- Box seekbox = new Box(Orientation.HORIZONTAL, 2);
- drawing_area.set_size_request(320, 240);
- hbox.pack_start(open_button, true, true, 0);
- hbox.pack_start(play_button, true, true, 0);
- seekbox.pack_start(rewind_button, true, true, 0);
- seekbox.pack_start(forward_button, true, true, 0);
- vbox.pack_start(drawing_area, true, true, 0);
- vbox.pack_start(seekbox, false, true, 0);
- vbox.pack_start(hbox, false, true, 0);
- add(vbox);
- play_button.clicked.connect(on_play);
- open_button.clicked.connect(on_open);
- rewind_button.clicked.connect(() => {on_seek(-5);});
- forward_button.clicked.connect(() => {on_seek(5);});
- destroy.connect (Gtk.main_quit);
- }
- public void on_seek(int seek)
- {
- if (state)
- {
- Format fmt = Format.TIME;
- int64 pos = 0;
- playbin.query_position(ref fmt, out pos);
- playbin.seek_simple(Format.TIME, SeekFlags.FLUSH | SeekFlags.ACCURATE, (pos + (seek * SECOND)));
- }
- }
- public void on_play()
- {
- if (state)
- {
- playbin.set_state(State.PAUSED);
- state = false;
- }
- else
- {
- playbin.set_state (State.PLAYING);
- state = true;
- }
- }
- public void create_playbin(string uri)
- {
- playbin.set_state(State.READY);
- playbin.uri = uri;
- playbin.video_sink = sink;
- sink.set("force-aspect-ratio", true);
- ((XOverlay) sink).set_xwindow_id (Gdk.X11Window.get_xid (drawing_area.get_window ()));
- }
- public void on_open()
- {
- var file_chooser = new FileChooserDialog("Select media", this, FileChooserAction.OPEN, Stock.CANCEL, ResponseType.CANCEL, Stock.OPEN, ResponseType.ACCEPT, null);
- if (file_chooser.run() == ResponseType.ACCEPT) create_playbin(file_chooser.get_uri());
- file_chooser.destroy();
- }
- }
- public static int main(string[] args)
- {
- Gtk.init(ref args);
- Gst.init(ref args);
- var app = new player_window();
- app.show_all();
- Gtk.main();
- return 0;
- }
Add Comment
Please, Sign In to add comment