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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
|
/*
* Copyright © 2018 Benjamin Otte
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#include "config.h"
#include "gtkvideo.h"
#include "gtkbinlayout.h"
#include "gtkeventcontrollermotion.h"
#include "gtkimage.h"
#include <glib/gi18n-lib.h>
#include "gtkmediacontrols.h"
#include "gtkmediafile.h"
#include "gtknative.h"
#include "gtkpicture.h"
#include "gtkrevealer.h"
#include "gtkwidgetprivate.h"
#include "gtkprivate.h"
/**
* GtkVideo:
*
* `GtkVideo` is a widget to show a `GtkMediaStream` with media controls.
*
* ![An example GtkVideo](video.png)
*
* The controls are available separately as [class@Gtk.MediaControls].
* If you just want to display a video without controls, you can treat it
* like any other paintable and for example put it into a [class@Gtk.Picture].
*
* `GtkVideo` aims to cover use cases such as previews, embedded animations,
* etc. It supports autoplay, looping, and simple media controls. It does
* not have support for video overlays, multichannel audio, device
* selection, or input. If you are writing a full-fledged video player,
* you may want to use the [iface@Gdk.Paintable] API and a media framework
* such as Gstreamer directly.
*/
struct _GtkVideo
{
GtkWidget parent_instance;
GFile *file;
GtkMediaStream *media_stream;
GtkWidget *box;
GtkWidget *video_picture;
GtkWidget *overlay_icon;
GtkWidget *controls_revealer;
GtkWidget *controls;
guint controls_hide_source;
guint autoplay : 1;
guint loop : 1;
guint grabbed : 1;
};
enum
{
PROP_0,
PROP_AUTOPLAY,
PROP_FILE,
PROP_LOOP,
PROP_MEDIA_STREAM,
N_PROPS
};
G_DEFINE_TYPE (GtkVideo, gtk_video, GTK_TYPE_WIDGET)
static GParamSpec *properties[N_PROPS] = { NULL, };
static gboolean
gtk_video_hide_controls (gpointer data)
{
GtkVideo *self = data;
if (self->grabbed)
return G_SOURCE_CONTINUE;
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), FALSE);
self->controls_hide_source = 0;
return G_SOURCE_REMOVE;
}
static void
gtk_video_reveal_controls (GtkVideo *self)
{
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), TRUE);
if (self->controls_hide_source)
g_source_remove (self->controls_hide_source);
self->controls_hide_source = g_timeout_add (5 * 1000,
gtk_video_hide_controls,
self);
gdk_source_set_static_name_by_id (self->controls_hide_source, "[gtk] gtk_video_hide_controls");
}
static void
gtk_video_motion (GtkEventControllerMotion *motion,
double x,
double y,
GtkVideo *self)
{
gtk_video_reveal_controls (self);
}
static void
gtk_video_pressed (GtkVideo *self)
{
gtk_video_reveal_controls (self);
}
static void
gtk_video_realize (GtkWidget *widget)
{
GtkVideo *self = GTK_VIDEO (widget);
GTK_WIDGET_CLASS (gtk_video_parent_class)->realize (widget);
if (self->media_stream)
{
GdkSurface *surface;
surface = gtk_native_get_surface (gtk_widget_get_native (widget));
gtk_media_stream_realize (self->media_stream, surface);
}
if (self->file)
gtk_media_file_set_file (GTK_MEDIA_FILE (self->media_stream), self->file);
}
static void
gtk_video_unrealize (GtkWidget *widget)
{
GtkVideo *self = GTK_VIDEO (widget);
if (self->autoplay && self->media_stream)
gtk_media_stream_pause (self->media_stream);
if (self->media_stream)
{
GdkSurface *surface;
surface = gtk_native_get_surface (gtk_widget_get_native (widget));
gtk_media_stream_unrealize (self->media_stream, surface);
}
GTK_WIDGET_CLASS (gtk_video_parent_class)->unrealize (widget);
}
static void
gtk_video_map (GtkWidget *widget)
{
GtkVideo *self = GTK_VIDEO (widget);
GTK_WIDGET_CLASS (gtk_video_parent_class)->map (widget);
if (self->autoplay &&
self->media_stream &&
gtk_media_stream_is_prepared (self->media_stream))
gtk_media_stream_play (self->media_stream);
}
static void
gtk_video_unmap (GtkWidget *widget)
{
GtkVideo *self = GTK_VIDEO (widget);
if (self->controls_hide_source)
{
g_source_remove (self->controls_hide_source);
self->controls_hide_source = 0;
gtk_revealer_set_reveal_child (GTK_REVEALER (self->controls_revealer), FALSE);
}
GTK_WIDGET_CLASS (gtk_video_parent_class)->unmap (widget);
}
static void
gtk_video_hide (GtkWidget *widget)
{
GtkVideo *self = GTK_VIDEO (widget);
if (self->autoplay && self->media_stream)
gtk_media_stream_pause (self->media_stream);
GTK_WIDGET_CLASS (gtk_video_parent_class)->hide (widget);
}
static void
gtk_video_set_focus_child (GtkWidget *widget,
GtkWidget *child)
{
GtkVideo *self = GTK_VIDEO (widget);
self->grabbed = child != NULL;
GTK_WIDGET_CLASS (gtk_video_parent_class)->set_focus_child (widget, child);
}
static void
gtk_video_dispose (GObject *object)
{
GtkVideo *self = GTK_VIDEO (object);
gtk_video_set_media_stream (self, NULL);
g_clear_pointer (&self->box, gtk_widget_unparent);
g_clear_object (&self->file);
G_OBJECT_CLASS (gtk_video_parent_class)->dispose (object);
}
static void
gtk_video_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GtkVideo *self = GTK_VIDEO (object);
switch (property_id)
{
case PROP_AUTOPLAY:
g_value_set_boolean (value, self->autoplay);
break;
case PROP_FILE:
g_value_set_object (value, self->file);
break;
case PROP_LOOP:
g_value_set_boolean (value, self->loop);
break;
case PROP_MEDIA_STREAM:
g_value_set_object (value, self->media_stream);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_video_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GtkVideo *self = GTK_VIDEO (object);
switch (property_id)
{
case PROP_AUTOPLAY:
gtk_video_set_autoplay (self, g_value_get_boolean (value));
break;
case PROP_FILE:
gtk_video_set_file (self, g_value_get_object (value));
break;
case PROP_LOOP:
gtk_video_set_loop (self, g_value_get_boolean (value));
break;
case PROP_MEDIA_STREAM:
gtk_video_set_media_stream (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gtk_video_class_init (GtkVideoClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
widget_class->realize = gtk_video_realize;
widget_class->unrealize = gtk_video_unrealize;
widget_class->map = gtk_video_map;
widget_class->unmap = gtk_video_unmap;
widget_class->hide = gtk_video_hide;
widget_class->set_focus_child = gtk_video_set_focus_child;
gobject_class->dispose = gtk_video_dispose;
gobject_class->get_property = gtk_video_get_property;
gobject_class->set_property = gtk_video_set_property;
/**
* GtkVideo:autoplay: (attributes org.gtk.Property.get=gtk_video_get_autoplay org.gtk.Property.set=gtk_video_set_autoplay)
*
* If the video should automatically begin playing.
*/
properties[PROP_AUTOPLAY] =
g_param_spec_boolean ("autoplay", NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkVideo:file: (attributes org.gtk.Property.get=gtk_video_get_file org.gtk.Property.set=gtk_video_set_file)
*
* The file played by this video if the video is playing a file.
*/
properties[PROP_FILE] =
g_param_spec_object ("file", NULL, NULL,
G_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkVideo:loop: (attributes org.gtk.Property.get=gtk_video_get_loop org.gtk.Property.set=gtk_video_set_loop)
*
* If new media files should be set to loop.
*/
properties[PROP_LOOP] =
g_param_spec_boolean ("loop", NULL, NULL,
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkVideo:media-stream: (attributes org.gtk.Property.get=gtk_video_get_media_stream org.gtk.Property.set=gtk_video_set_media_stream)
*
* The media-stream played
*/
properties[PROP_MEDIA_STREAM] =
g_param_spec_object ("media-stream", NULL, NULL,
GTK_TYPE_MEDIA_STREAM,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkvideo.ui");
gtk_widget_class_bind_template_child (widget_class, GtkVideo, box);
gtk_widget_class_bind_template_child (widget_class, GtkVideo, video_picture);
gtk_widget_class_bind_template_child (widget_class, GtkVideo, overlay_icon);
gtk_widget_class_bind_template_child (widget_class, GtkVideo, controls);
gtk_widget_class_bind_template_child (widget_class, GtkVideo, controls_revealer);
gtk_widget_class_bind_template_callback (widget_class, gtk_video_motion);
gtk_widget_class_bind_template_callback (widget_class, gtk_video_pressed);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("video"));
}
static void
gtk_video_init (GtkVideo *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
/**
* gtk_video_new:
*
* Creates a new empty `GtkVideo`.
*
* Returns: a new `GtkVideo`
*/
GtkWidget *
gtk_video_new (void)
{
return g_object_new (GTK_TYPE_VIDEO, NULL);
}
/**
* gtk_video_new_for_media_stream:
* @stream: (nullable): a `GtkMediaStream`
*
* Creates a `GtkVideo` to play back the given @stream.
*
* Returns: a new `GtkVideo`
*/
GtkWidget *
gtk_video_new_for_media_stream (GtkMediaStream *stream)
{
g_return_val_if_fail (stream == NULL || GTK_IS_MEDIA_STREAM (stream), NULL);
return g_object_new (GTK_TYPE_VIDEO,
"media-stream", stream,
NULL);
}
/**
* gtk_video_new_for_file:
* @file: (nullable): a `GFile`
*
* Creates a `GtkVideo` to play back the given @file.
*
* Returns: a new `GtkVideo`
*/
GtkWidget *
gtk_video_new_for_file (GFile *file)
{
g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL);
return g_object_new (GTK_TYPE_VIDEO,
"file", file,
NULL);
}
/**
* gtk_video_new_for_filename:
* @filename: (nullable) (type filename): filename to play back
*
* Creates a `GtkVideo` to play back the given @filename.
*
* This is a utility function that calls [ctor@Gtk.Video.new_for_file],
* See that function for details.
*
* Returns: a new `GtkVideo`
*/
GtkWidget *
gtk_video_new_for_filename (const char *filename)
{
GtkWidget *result;
GFile *file;
if (filename)
file = g_file_new_for_path (filename);
else
file = NULL;
result = gtk_video_new_for_file (file);
if (file)
g_object_unref (file);
return result;
}
/**
* gtk_video_new_for_resource:
* @resource_path: (nullable): resource path to play back
*
* Creates a `GtkVideo` to play back the resource at the
* given @resource_path.
*
* This is a utility function that calls [ctor@Gtk.Video.new_for_file].
*
* Returns: a new `GtkVideo`
*/
GtkWidget *
gtk_video_new_for_resource (const char *resource_path)
{
GtkWidget *result;
GFile *file;
if (resource_path)
{
char *uri, *escaped;
escaped = g_uri_escape_string (resource_path,
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
uri = g_strconcat ("resource://", escaped, NULL);
g_free (escaped);
file = g_file_new_for_uri (uri);
g_free (uri);
}
else
{
file = NULL;
}
result = gtk_video_new_for_file (file);
if (file)
g_object_unref (file);
return result;
}
/**
* gtk_video_get_media_stream: (attributes org.gtk.Method.get_property=media-stream)
* @self: a `GtkVideo`
*
* Gets the media stream managed by @self or %NULL if none.
*
* Returns: (nullable) (transfer none): The media stream managed by @self
*/
GtkMediaStream *
gtk_video_get_media_stream (GtkVideo *self)
{
g_return_val_if_fail (GTK_IS_VIDEO (self), NULL);
return self->media_stream;
}
static void
gtk_video_update_overlay_icon (GtkVideo *self)
{
const char *icon_name;
const GError *error = NULL;
if (self->media_stream == NULL)
icon_name = "media-eject-symbolic";
else if ((error = gtk_media_stream_get_error (self->media_stream)))
icon_name = "dialog-error-symbolic";
else if (gtk_media_stream_get_ended (self->media_stream))
icon_name = "media-playlist-repeat-symbolic";
else
icon_name = "media-playback-start-symbolic";
gtk_image_set_from_icon_name (GTK_IMAGE (self->overlay_icon), icon_name);
if (error)
gtk_widget_set_tooltip_text (self->overlay_icon, error->message);
else
gtk_widget_set_tooltip_text (self->overlay_icon, NULL);
}
static void
gtk_video_update_ended (GtkVideo *self)
{
gtk_video_update_overlay_icon (self);
}
static void
gtk_video_update_error (GtkVideo *self)
{
gtk_video_update_overlay_icon (self);
}
static void
gtk_video_update_playing (GtkVideo *self)
{
gboolean playing;
if (self->media_stream != NULL)
playing = gtk_media_stream_get_playing (self->media_stream);
else
playing = FALSE;
gtk_widget_set_visible (self->overlay_icon, !playing);
}
static void
gtk_video_update_all (GtkVideo *self)
{
gtk_video_update_ended (self);
gtk_video_update_error (self);
gtk_video_update_playing (self);
}
static void
gtk_video_notify_cb (GtkMediaStream *stream,
GParamSpec *pspec,
GtkVideo *self)
{
if (g_str_equal (pspec->name, "ended"))
gtk_video_update_ended (self);
if (g_str_equal (pspec->name, "error"))
gtk_video_update_error (self);
if (g_str_equal (pspec->name, "playing"))
gtk_video_update_playing (self);
if (g_str_equal (pspec->name, "prepared"))
{
if (self->autoplay &&
gtk_media_stream_is_prepared (stream) &&
gtk_widget_get_mapped (GTK_WIDGET (self)))
gtk_media_stream_play (stream);
}
}
/**
* gtk_video_set_media_stream: (attributes org.gtk.Method.set_property=media-stream)
* @self: a `GtkVideo`
* @stream: (nullable): The media stream to play or %NULL to unset
*
* Sets the media stream to be played back.
*
* @self will take full control of managing the media stream. If you
* want to manage a media stream yourself, consider using a
* [class@Gtk.Picture] for display.
*
* If you want to display a file, consider using [method@Gtk.Video.set_file]
* instead.
*/
void
gtk_video_set_media_stream (GtkVideo *self,
GtkMediaStream *stream)
{
g_return_if_fail (GTK_IS_VIDEO (self));
g_return_if_fail (stream == NULL || GTK_IS_MEDIA_STREAM (stream));
if (self->media_stream == stream)
return;
if (self->media_stream)
{
if (self->autoplay)
gtk_media_stream_pause (self->media_stream);
g_signal_handlers_disconnect_by_func (self->media_stream,
gtk_video_notify_cb,
self);
if (gtk_widget_get_realized (GTK_WIDGET (self)))
{
GdkSurface *surface;
surface = gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (self)));
gtk_media_stream_unrealize (self->media_stream, surface);
}
g_object_unref (self->media_stream);
self->media_stream = NULL;
}
if (stream)
{
self->media_stream = g_object_ref (stream);
gtk_media_stream_set_loop (stream, self->loop);
if (gtk_widget_get_realized (GTK_WIDGET (self)))
{
GdkSurface *surface;
surface = gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (self)));
gtk_media_stream_realize (stream, surface);
}
g_signal_connect (self->media_stream,
"notify",
G_CALLBACK (gtk_video_notify_cb),
self);
if (self->autoplay &&
gtk_media_stream_is_prepared (stream) &&
gtk_widget_get_mapped (GTK_WIDGET (self)))
gtk_media_stream_play (stream);
}
gtk_media_controls_set_media_stream (GTK_MEDIA_CONTROLS (self->controls), stream);
gtk_picture_set_paintable (GTK_PICTURE (self->video_picture), GDK_PAINTABLE (stream));
gtk_video_update_all (self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MEDIA_STREAM]);
}
/**
* gtk_video_get_file: (attributes org.gtk.Method.get_property=file)
* @self: a `GtkVideo`
*
* Gets the file played by @self or %NULL if not playing back
* a file.
*
* Returns: (nullable) (transfer none): The file played by @self
*/
GFile *
gtk_video_get_file (GtkVideo *self)
{
g_return_val_if_fail (GTK_IS_VIDEO (self), NULL);
return self->file;
}
/**
* gtk_video_set_file: (attributes org.gtk.Method.set_property=file)
* @self: a `GtkVideo`
* @file: (nullable): the file to play
*
* Makes @self play the given @file.
*/
void
gtk_video_set_file (GtkVideo *self,
GFile *file)
{
g_return_if_fail (GTK_IS_VIDEO (self));
g_return_if_fail (file == NULL || G_IS_FILE (file));
if (!g_set_object (&self->file, file))
return;
g_object_freeze_notify (G_OBJECT (self));
if (file)
{
GtkMediaStream *stream;
stream = gtk_media_file_new ();
if (gtk_widget_get_realized (GTK_WIDGET (self)))
{
GdkSurface *surface;
surface = gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (self)));
gtk_media_stream_realize (stream, surface);
gtk_media_file_set_file (GTK_MEDIA_FILE (stream), file);
}
gtk_video_set_media_stream (self, stream);
g_object_unref (stream);
}
else
{
gtk_video_set_media_stream (self, NULL);
}
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FILE]);
g_object_thaw_notify (G_OBJECT (self));
}
/**
* gtk_video_set_filename:
* @self: a `GtkVideo`
* @filename: (type filename) (nullable): the filename to play
*
* Makes @self play the given @filename.
*
* This is a utility function that calls gtk_video_set_file(),
*/
void
gtk_video_set_filename (GtkVideo *self,
const char *filename)
{
GFile *file;
g_return_if_fail (GTK_IS_VIDEO (self));
if (filename)
file = g_file_new_for_path (filename);
else
file = NULL;
gtk_video_set_file (self, file);
if (file)
g_object_unref (file);
}
/**
* gtk_video_set_resource:
* @self: a `GtkVideo`
* @resource_path: (nullable): the resource to set
*
* Makes @self play the resource at the given @resource_path.
*
* This is a utility function that calls [method@Gtk.Video.set_file].
*/
void
gtk_video_set_resource (GtkVideo *self,
const char *resource_path)
{
GFile *file;
g_return_if_fail (GTK_IS_VIDEO (self));
if (resource_path)
{
char *uri, *escaped;
escaped = g_uri_escape_string (resource_path,
G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, FALSE);
uri = g_strconcat ("resource://", escaped, NULL);
g_free (escaped);
file = g_file_new_for_uri (uri);
g_free (uri);
}
else
{
file = NULL;
}
gtk_video_set_file (self, file);
if (file)
g_object_unref (file);
}
/**
* gtk_video_get_autoplay: (attributes org.gtk.Method.get_property=autoplay)
* @self: a `GtkVideo`
*
* Returns %TRUE if videos have been set to loop.
*
* Returns: %TRUE if streams should autoplay
*/
gboolean
gtk_video_get_autoplay (GtkVideo *self)
{
g_return_val_if_fail (GTK_IS_VIDEO (self), FALSE);
return self->autoplay;
}
/**
* gtk_video_set_autoplay: (attributes org.gtk.Method.set_property=autoplay)
* @self: a `GtkVideo`
* @autoplay: whether media streams should autoplay
*
* Sets whether @self automatically starts playback when it
* becomes visible or when a new file gets loaded.
*/
void
gtk_video_set_autoplay (GtkVideo *self,
gboolean autoplay)
{
g_return_if_fail (GTK_IS_VIDEO (self));
if (self->autoplay == autoplay)
return;
self->autoplay = autoplay;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_AUTOPLAY]);
}
/**
* gtk_video_get_loop: (attributes org.gtk.Method.get_property=loop)
* @self: a `GtkVideo`
*
* Returns %TRUE if videos have been set to loop.
*
* Returns: %TRUE if streams should loop
*/
gboolean
gtk_video_get_loop (GtkVideo *self)
{
g_return_val_if_fail (GTK_IS_VIDEO (self), FALSE);
return self->loop;
}
/**
* gtk_video_set_loop: (attributes org.gtk.Method.set_property=loop)
* @self: a `GtkVideo`
* @loop: whether media streams should loop
*
* Sets whether new files loaded by @self should be set to loop.
*/
void
gtk_video_set_loop (GtkVideo *self,
gboolean loop)
{
g_return_if_fail (GTK_IS_VIDEO (self));
if (self->loop == loop)
return;
self->loop = loop;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOOP]);
}
|