Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // compile with : valac test-gtk4.vala --pkg gio-unix-2.0 --pkg gtk4
- public class Pipe : IOStream {
- int fds[2];
- OutputStream ostream;
- InputStream istream;
- construct {
- Unix.open_pipe (fds, 0);
- input_fd = fds[0]; output_fd = fds[1];
- istream = new UnixInputStream (fds[0], false);
- ostream = new UnixOutputStream (fds[1], false);
- }
- public int input_fd { get; private set; }
- public int output_fd { get; private set; }
- public override InputStream input_stream {
- get {
- return istream;
- }
- }
- public override OutputStream output_stream {
- get {
- return ostream;
- }
- }
- }
- public class VideoWriter : Pipe {
- Gtk.Video video;
- public VideoWriter (Gtk.Video video) {
- this.video = video;
- }
- async void write_to_pipe (InputStream stream) {
- new Thread<void*>("write", () => {
- output_stream.splice (stream, OutputStreamSpliceFlags.NONE);
- Idle.add (write_to_pipe.callback);
- return null;
- });
- yield;
- }
- public void set_input_stream (InputStream stream) {
- write_to_pipe.begin (stream, (obj, res) => {
- });
- video.set_file (File.new_for_path ("/dev/fd/" + input_fd.to_string()));
- }
- }
- public static void main (string[] args) {
- Gtk.init();
- var proc = new Subprocess (SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDIN_PIPE | SubprocessFlags.STDERR_PIPE, "streamlink", "-O", "https://www.france.tv/france-2/direct.html", "best");
- var loop = new MainLoop();
- var win = new Gtk.Window();
- var vid = new Gtk.Video();
- var writer = new VideoWriter (vid);
- vid.set_autoplay (true);
- vid.realize.connect (() => {
- writer.set_input_stream (proc.get_stdout_pipe());
- });
- win.child = vid;
- (win as Gtk.Widget).unrealize.connect (loop.quit);
- win.set_size_request (400, 300);
- win.show();
- loop.run();
- }
Add Comment
Please, Sign In to add comment