-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.clay
95 lines (70 loc) · 2.52 KB
/
test.clay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gtk.*;
import gobject.*;
import gstreamer.*;
import glib.*;
import printer.(println,
printlnTo);
import data.strings.(String);
import io.files.(stderr);
private external watchBus(bus: Pointer[GstBus], message: Pointer[GstMessage], data: gpointer) : gboolean {
var msgType = message^.type;
println(String(gst_message_type_get_name(msgType)));
if (msgType == GST_MESSAGE_ERROR) {
var err = null(GError);
var debugInfo = null(gchar);
gst_message_parse_error(message, @err, @debugInfo);
println("Error: ", String(err^.message));
println("debug info: ", String(debugInfo));
g_error_free(err);
g_free(gpointer(debugInfo));
gst_element_set_state(playbin, GST_STATE_NULL);
}
return TRUE;
}
private external togglePlaying(widget: Pointer[GtkWidget], data: gpointer) {
var button = Pointer[GtkButton](widget);
if (playing) {
gst_element_set_state(playbin, GST_STATE_PAUSED);
gtk_button_set_label(button, cstring("Start"));
} else {
gst_element_set_state(playbin, GST_STATE_PLAYING);
gtk_button_set_label(button, cstring("Pause"));
}
playing = not(playing);
}
private external destroying(widget: Pointer[GtkWidget], data: gpointer) {
gtk_main_quit();
}
private var playbin = null(GstElement);
private var playing = false;
main(argc, argv) {
gtk_init(@argc, @argv);
gst_init(@argc, @argv);
if (argc != 2) {
printlnTo(stderr, "Usage: test URI");
return 1;
}
var uri = argv[1];
// gstreamer setup
playbin = gst_element_factory_make(cstring("playbin2"), cstring("play"));
var bus = gst_pipeline_get_bus(Pointer[GstPipeline](playbin));
gst_bus_add_watch(bus, GstBusFunc(watchBus), gpointer(0));
gst_object_unref(gpointer(bus));
g_object_set(gpointer(playbin), cstring("uri"), uri, 0);
// gtk setup
var window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gSignalConnect(window, cstring("destroy"),
GCallback(destroying), gpointer(0));
gtk_container_set_border_width(Pointer[GtkContainer](window), 10u);
var button = gtk_button_new_with_label(cstring("Start"));
gSignalConnect(button, cstring("clicked"),
GCallback(togglePlaying), gpointer(0));
gtk_container_add(Pointer[GtkContainer](window), button);
gtk_widget_show(button);
gtk_widget_show(window);
gtk_main();
// some gstreamer cleanup
gst_element_set_state(playbin, GST_STATE_NULL);
gst_object_unref(gpointer(playbin));
return 0;
}