[Gtk] layout.ui
播放器layout:
#
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="main_window">
<property name="title">GTK Video Player</property>
<property name="default-width">1200</property>
<property name="default-height">600</property>
<child>
<object class="GtkBox" id="main_hbox">
<property name="orientation">horizontal</property>
<property name="spacing">5</property>
<!-- Left Sidebar -->
<child>
<object class="GtkBox" id="sidebar">
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<property name="width-request">150</property> <!-- Fixed width of sidebar -->
<!-- Add 10 Buttons to the sidebar -->
<child>
<object class="GtkButton" id="button_1">
<property name="label">Button 1</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_2">
<property name="label">Button 2</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_3">
<property name="label">Button 3</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_4">
<property name="label">Button 4</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_5">
<property name="label">Button 5</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_6">
<property name="label">Button 6</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_7">
<property name="label">Button 7</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_8">
<property name="label">Button 8</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_9">
<property name="label">Button 9</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_10">
<property name="label">Button 10</property>
</object>
</child>
</object>
</child>
<!-- Center Video Area -->
<child>
<object class="GtkDrawingArea" id="video_area">
<property name="hexpand">true</property>
<property name="vexpand">true</property>
</object>
</child>
<!-- Right Text Output Area -->
<child>
<object class="GtkTextView" id="text_view">
<property name="width-request">300</property> <!-- Fixed width for text output -->
<property name="hexpand">false</property>
<property name="vexpand">true</property>
</object>
</child>
</object>
</child>
</object>
</interface>
#include <gtk/gtk.h>
#include <gst/gst.h>
#include <gst/video/videooverlay.h>
static GstElement *pipeline;
static void realize_cb(GtkWidget *widget, gpointer data) {
GdkWindow *window = gtk_widget_get_window(widget);
guintptr window_handle = GDK_WINDOW_XID(window);
GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(pipeline);
gst_video_overlay_set_window_handle(overlay, window_handle);
}
static void activate(GtkApplication *app, gpointer user_data) {
GtkBuilder *builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "layout.ui", NULL);
GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
GtkWidget *drawing_area = GTK_WIDGET(gtk_builder_get_object(builder, "video_area"));
g_signal_connect(drawing_area, "realize", G_CALLBACK(realize_cb), NULL);
gtk_widget_show_all(window);
// 创建 GStreamer 管道并播放视频
pipeline = gst_parse_launch("playbin uri=file:///path/to/video", NULL);
GstVideoOverlay *overlay = GST_VIDEO_OVERLAY(pipeline);
gst_video_overlay_set_window_handle(overlay, GDK_WINDOW_XID(gtk_widget_get_window(drawing_area)));
gst_element_set_state(pipeline, GST_STATE_PLAYING);
}
int main(int argc, char **argv) {
GtkApplication *app;
int status;
gst_init(&argc, &argv);
app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run(G_APPLICATION(app), argc, argv);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
g_object_unref(app);
return status;
}
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow" id="main_window">
<property name="title">GTK Video Player</property>
<property name="default-width">1200</property>
<property name="default-height">600</property>
<child>
<object class="GtkBox" id="main_hbox">
<property name="orientation">horizontal</property>
<property name="spacing">5</property>
<!-- Left Sidebar with scrollable content -->
<child>
<object class="GtkScrolledWindow" id="scrolled_sidebar">
<property name="width-request">150</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<child>
<object class="GtkViewport">
<child>
<object class="GtkBox" id="sidebar">
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<!-- Add 10 Buttons to the sidebar -->
<child>
<object class="GtkButton" id="button_1">
<property name="label">Button 1</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_2">
<property name="label">Button 2</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_3">
<property name="label">Button 3</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_4">
<property name="label">Button 4</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_5">
<property name="label">Button 5</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_6">
<property name="label">Button 6</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_7">
<property name="label">Button 7</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_8">
<property name="label">Button 8</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_9">
<property name="label">Button 9</property>
</object>
</child>
<child>
<object class="GtkButton" id="button_10">
<property name="label">Button 10</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Separator between sidebar and drawing area -->
<child>
<object class="GtkSeparator" id="separator">
<property name="orientation">vertical</property>
</object>
</child>
<!-- Center Video Area -->
<child>
<object class="GtkDrawingArea" id="video_area">
<property name="hexpand">true</property>
<property name="vexpand">true</property>
</object>
</child>
<!-- Right Text Output Area -->
<child>
<object class="GtkTextView" id="text_view">
<property name="width-request">300</property>
<property name="hexpand">false</property>
<property name="vexpand">true</property>
</object>
</child>
</object>
</child>
</object>
</interface>