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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
#include "config.h"
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include "bacon-video-widget.h"
#ifdef GDK_WINDOWING_X11
#include <X11/Xlib.h>
#endif
static char **filenames;
static const char *argument;
static char *mrl;
static void
test_bvw_set_mrl (GtkWidget *bvw, const char *path)
{
mrl = g_strdup (path);
bacon_video_widget_open (BACON_VIDEO_WIDGET (bvw), mrl);
}
static void
on_redirect (GtkWidget *bvw, const char *redirect_mrl, gpointer data)
{
g_message ("Redirect to: %s", redirect_mrl);
}
static void
on_eos_event (GtkWidget *bvw, gpointer user_data)
{
bacon_video_widget_stop (BACON_VIDEO_WIDGET (bvw));
bacon_video_widget_close (BACON_VIDEO_WIDGET (bvw));
g_free (mrl);
test_bvw_set_mrl (bvw, argument);
bacon_video_widget_play (BACON_VIDEO_WIDGET (bvw), NULL);
}
static void
on_got_metadata (BaconVideoWidget *bvw, gpointer data)
{
GValue value = { 0, };
char *title, *artist;
bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
BVW_INFO_TITLE, &value);
title = g_value_dup_string (&value);
g_value_unset (&value);
bacon_video_widget_get_metadata (BACON_VIDEO_WIDGET (bvw),
BVW_INFO_ARTIST, &value);
artist = g_value_dup_string (&value);
g_value_unset (&value);
g_message ("Got metadata: title = %s artist = %s", title, artist);
}
static void
error_cb (GtkWidget *bvw, const char *message,
gboolean playback_stopped, gboolean fatal)
{
g_message ("Error: %s, playback stopped: %d, fatal: %d",
message, playback_stopped, fatal);
}
static GOptionEntry option_entries [] = {
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY /* STRING? */, &filenames, NULL },
{ NULL }
};
int main
(int argc, char **argv)
{
GOptionContext *context;
GOptionGroup *baconoptiongroup;
GError *error = NULL;
GtkWidget *win, *bvw;
GtkSettings *gtk_settings;
GtkBox *box;
GtkToolItem *item;
GtkWidget *image;
#ifdef GDK_WINDOWING_X11
XInitThreads ();
#endif
if (gtk_clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS)
g_assert_not_reached ();
context = g_option_context_new ("- Play audio and video inside a web browser");
baconoptiongroup = bacon_video_widget_get_option_group();
g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE);
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
g_option_context_add_group (context, baconoptiongroup);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
g_print ("Failed to parse options: %s\n", error->message);
g_error_free (error);
return 1;
}
if (filenames != NULL &&
g_strv_length (filenames) > 1) {
char *help;
help = g_option_context_get_help (context, TRUE, NULL);
g_print ("%s", help);
g_free (help);
return 1;
}
gtk_settings = gtk_settings_get_default ();
g_object_set (G_OBJECT (gtk_settings), "gtk-application-prefer-dark-theme", TRUE, NULL);
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (win), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
bvw = bacon_video_widget_new (NULL);
g_signal_connect (G_OBJECT (bvw), "eos", G_CALLBACK (on_eos_event), NULL);
g_signal_connect (G_OBJECT (bvw), "got-metadata", G_CALLBACK (on_got_metadata), NULL);
g_signal_connect (G_OBJECT (bvw), "got-redirect", G_CALLBACK (on_redirect), NULL);
g_signal_connect (G_OBJECT (bvw), "error", G_CALLBACK (error_cb), NULL);
box = g_object_get_data (bacon_video_widget_get_controls_object (BACON_VIDEO_WIDGET (bvw)), "controls_box");
/* Previous */
item = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "media-skip-backward-symbolic");
gtk_box_pack_start (box, GTK_WIDGET (item), FALSE, FALSE, 0);
/* Play/Pause */
item = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "media-playback-start-symbolic");
gtk_box_pack_start (box, GTK_WIDGET (item), FALSE, FALSE, 0);
/* Next */
item = gtk_tool_button_new (NULL, NULL);
gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "media-skip-forward-symbolic");
gtk_box_pack_start (box, GTK_WIDGET (item), FALSE, FALSE, 0);
/* Separator */
item = gtk_separator_tool_item_new ();
gtk_box_pack_start (box, GTK_WIDGET (item), FALSE, FALSE, 0);
/* Go button */
item = g_object_get_data (bacon_video_widget_get_controls_object (BACON_VIDEO_WIDGET (bvw)), "go_button");
image = gtk_image_new_from_icon_name ("view-more-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_button_set_image (GTK_BUTTON (item), image);
gtk_widget_show_all (GTK_WIDGET (box));
gtk_container_add (GTK_CONTAINER (win),bvw);
gtk_widget_realize (GTK_WIDGET (win));
gtk_widget_realize (bvw);
gtk_widget_show (win);
gtk_widget_show (bvw);
if (filenames && filenames[0]) {
test_bvw_set_mrl (bvw, filenames[0]);
argument = g_strdup (filenames[0]);
bacon_video_widget_play (BACON_VIDEO_WIDGET (bvw), NULL);
}
gtk_main ();
return 0;
}
|