gtk4/auto/media_file.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, MediaStream};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 /// [`MediaFile`][crate::MediaFile] implements [`MediaStream`][crate::MediaStream] for files.
15 ///
16 /// This provides a simple way to play back video files with GTK.
17 ///
18 /// GTK provides a GIO extension point for [`MediaFile`][crate::MediaFile] implementations
19 /// to allow for external implementations using various media frameworks.
20 ///
21 /// GTK itself includes an implementation using GStreamer.
22 ///
23 /// This is an Abstract Base Class, you cannot instantiate it.
24 ///
25 /// ## Properties
26 ///
27 ///
28 /// #### `file`
29 /// The file being played back or [`None`] if not playing a file.
30 ///
31 /// Readable | Writeable
32 ///
33 ///
34 /// #### `input-stream`
35 /// The stream being played back or [`None`] if not playing a stream.
36 ///
37 /// This is [`None`] when playing a file.
38 ///
39 /// Readable | Writeable
40 /// <details><summary><h4>MediaStream</h4></summary>
41 ///
42 ///
43 /// #### `duration`
44 /// The stream's duration in microseconds or 0 if unknown.
45 ///
46 /// Readable
47 ///
48 ///
49 /// #### `ended`
50 /// Set when playback has finished.
51 ///
52 /// Readable
53 ///
54 ///
55 /// #### `error`
56 /// [`None`] for a properly working stream or the `GError`
57 /// that the stream is in.
58 ///
59 /// Readable
60 ///
61 ///
62 /// #### `has-audio`
63 /// Whether the stream contains audio.
64 ///
65 /// Readable
66 ///
67 ///
68 /// #### `has-video`
69 /// Whether the stream contains video.
70 ///
71 /// Readable
72 ///
73 ///
74 /// #### `loop`
75 /// Try to restart the media from the beginning once it ended.
76 ///
77 /// Readable | Writeable
78 ///
79 ///
80 /// #### `muted`
81 /// Whether the audio stream should be muted.
82 ///
83 /// Readable | Writeable
84 ///
85 ///
86 /// #### `playing`
87 /// Whether the stream is currently playing.
88 ///
89 /// Readable | Writeable
90 ///
91 ///
92 /// #### `prepared`
93 /// Whether the stream has finished initializing and existence of
94 /// audio and video is known.
95 ///
96 /// Readable | Writeable
97 ///
98 ///
99 /// #### `seekable`
100 /// Set unless the stream is known to not support seeking.
101 ///
102 /// Readable
103 ///
104 ///
105 /// #### `seeking`
106 /// Set while a seek is in progress.
107 ///
108 /// Readable
109 ///
110 ///
111 /// #### `timestamp`
112 /// The current presentation timestamp in microseconds.
113 ///
114 /// Readable
115 ///
116 ///
117 /// #### `volume`
118 /// Volume of the audio stream.
119 ///
120 /// Readable | Writeable
121 /// </details>
122 ///
123 /// # Implements
124 ///
125 /// [`MediaFileExt`][trait@crate::prelude::MediaFileExt], [`MediaStreamExt`][trait@crate::prelude::MediaStreamExt], [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`MediaStreamExtManual`][trait@crate::prelude::MediaStreamExtManual]
126 #[doc(alias = "GtkMediaFile")]
127 pub struct MediaFile(Object<ffi::GtkMediaFile, ffi::GtkMediaFileClass>) @extends MediaStream, @implements gdk::Paintable;
128
129 match fn {
130 type_ => || ffi::gtk_media_file_get_type(),
131 }
132}
133
134impl MediaFile {
135 pub const NONE: Option<&'static MediaFile> = None;
136
137 /// Creates a new empty media file.
138 ///
139 /// # Returns
140 ///
141 /// a new [`MediaFile`][crate::MediaFile]
142 #[doc(alias = "gtk_media_file_new")]
143 pub fn new() -> MediaFile {
144 assert_initialized_main_thread!();
145 unsafe { from_glib_full(ffi::gtk_media_file_new()) }
146 }
147
148 /// Creates a new media file to play @file.
149 /// ## `file`
150 /// The file to play
151 ///
152 /// # Returns
153 ///
154 /// a new [`MediaFile`][crate::MediaFile] playing @file
155 #[doc(alias = "gtk_media_file_new_for_file")]
156 #[doc(alias = "new_for_file")]
157 pub fn for_file(file: &impl IsA<gio::File>) -> MediaFile {
158 assert_initialized_main_thread!();
159 unsafe {
160 from_glib_full(ffi::gtk_media_file_new_for_file(
161 file.as_ref().to_glib_none().0,
162 ))
163 }
164 }
165
166 /// Creates a new media file for the given filename.
167 ///
168 /// This is a utility function that converts the given @filename
169 /// to a `GFile` and calls [`for_file()`][Self::for_file()].
170 /// ## `filename`
171 /// filename to open
172 ///
173 /// # Returns
174 ///
175 /// a new [`MediaFile`][crate::MediaFile] playing @filename
176 #[doc(alias = "gtk_media_file_new_for_filename")]
177 #[doc(alias = "new_for_filename")]
178 pub fn for_filename(filename: impl AsRef<std::path::Path>) -> MediaFile {
179 assert_initialized_main_thread!();
180 unsafe {
181 from_glib_full(ffi::gtk_media_file_new_for_filename(
182 filename.as_ref().to_glib_none().0,
183 ))
184 }
185 }
186
187 /// Creates a new media file to play @stream.
188 ///
189 /// If you want the resulting media to be seekable,
190 /// the stream should implement the `GSeekable` interface.
191 /// ## `stream`
192 /// The stream to play
193 ///
194 /// # Returns
195 ///
196 /// a new [`MediaFile`][crate::MediaFile]
197 #[doc(alias = "gtk_media_file_new_for_input_stream")]
198 #[doc(alias = "new_for_input_stream")]
199 pub fn for_input_stream(stream: &impl IsA<gio::InputStream>) -> MediaFile {
200 assert_initialized_main_thread!();
201 unsafe {
202 from_glib_full(ffi::gtk_media_file_new_for_input_stream(
203 stream.as_ref().to_glib_none().0,
204 ))
205 }
206 }
207
208 /// Creates a new new media file for the given resource.
209 ///
210 /// This is a utility function that converts the given @resource
211 /// to a `GFile` and calls [`for_file()`][Self::for_file()].
212 /// ## `resource_path`
213 /// resource path to open
214 ///
215 /// # Returns
216 ///
217 /// a new [`MediaFile`][crate::MediaFile] playing @resource_path
218 #[doc(alias = "gtk_media_file_new_for_resource")]
219 #[doc(alias = "new_for_resource")]
220 pub fn for_resource(resource_path: &str) -> MediaFile {
221 assert_initialized_main_thread!();
222 unsafe {
223 from_glib_full(ffi::gtk_media_file_new_for_resource(
224 resource_path.to_glib_none().0,
225 ))
226 }
227 }
228}
229
230impl Default for MediaFile {
231 fn default() -> Self {
232 Self::new()
233 }
234}
235
236mod sealed {
237 pub trait Sealed {}
238 impl<T: super::IsA<super::MediaFile>> Sealed for T {}
239}
240
241/// Trait containing all [`struct@MediaFile`] methods.
242///
243/// # Implementors
244///
245/// [`MediaFile`][struct@crate::MediaFile]
246pub trait MediaFileExt: IsA<MediaFile> + sealed::Sealed + 'static {
247 /// Resets the media file to be empty.
248 #[doc(alias = "gtk_media_file_clear")]
249 fn clear(&self) {
250 unsafe {
251 ffi::gtk_media_file_clear(self.as_ref().to_glib_none().0);
252 }
253 }
254
255 /// Returns the file that @self is currently playing from.
256 ///
257 /// When @self is not playing or not playing from a file,
258 /// [`None`] is returned.
259 ///
260 /// # Returns
261 ///
262 /// The currently playing file
263 #[doc(alias = "gtk_media_file_get_file")]
264 #[doc(alias = "get_file")]
265 fn file(&self) -> Option<gio::File> {
266 unsafe { from_glib_none(ffi::gtk_media_file_get_file(self.as_ref().to_glib_none().0)) }
267 }
268
269 /// Returns the stream that @self is currently playing from.
270 ///
271 /// When @self is not playing or not playing from a stream,
272 /// [`None`] is returned.
273 ///
274 /// # Returns
275 ///
276 /// The currently playing stream
277 #[doc(alias = "gtk_media_file_get_input_stream")]
278 #[doc(alias = "get_input_stream")]
279 #[doc(alias = "input-stream")]
280 fn input_stream(&self) -> Option<gio::InputStream> {
281 unsafe {
282 from_glib_none(ffi::gtk_media_file_get_input_stream(
283 self.as_ref().to_glib_none().0,
284 ))
285 }
286 }
287
288 /// Sets the [`MediaFile`][crate::MediaFile] to play the given file.
289 ///
290 /// If any file is still playing, stop playing it.
291 /// ## `file`
292 /// the file to play
293 #[doc(alias = "gtk_media_file_set_file")]
294 #[doc(alias = "file")]
295 fn set_file(&self, file: Option<&impl IsA<gio::File>>) {
296 unsafe {
297 ffi::gtk_media_file_set_file(
298 self.as_ref().to_glib_none().0,
299 file.map(|p| p.as_ref()).to_glib_none().0,
300 );
301 }
302 }
303
304 /// Sets the [`MediaFile`][crate::MediaFile] to play the given file.
305 ///
306 /// This is a utility function that converts the given @filename
307 /// to a `GFile` and calls [`set_file()`][Self::set_file()].
308 /// ## `filename`
309 /// name of file to play
310 #[doc(alias = "gtk_media_file_set_filename")]
311 fn set_filename(&self, filename: Option<impl AsRef<std::path::Path>>) {
312 unsafe {
313 ffi::gtk_media_file_set_filename(
314 self.as_ref().to_glib_none().0,
315 filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
316 );
317 }
318 }
319
320 /// Sets the [`MediaFile`][crate::MediaFile] to play the given stream.
321 ///
322 /// If anything is still playing, stop playing it.
323 ///
324 /// Full control about the @stream is assumed for the duration of
325 /// playback. The stream will not be closed.
326 /// ## `stream`
327 /// the stream to play from
328 #[doc(alias = "gtk_media_file_set_input_stream")]
329 #[doc(alias = "input-stream")]
330 fn set_input_stream(&self, stream: Option<&impl IsA<gio::InputStream>>) {
331 unsafe {
332 ffi::gtk_media_file_set_input_stream(
333 self.as_ref().to_glib_none().0,
334 stream.map(|p| p.as_ref()).to_glib_none().0,
335 );
336 }
337 }
338
339 /// Sets the [`MediaFile`][crate::MediaFile] to play the given resource.
340 ///
341 /// This is a utility function that converts the given @resource_path
342 /// to a `GFile` and calls [`set_file()`][Self::set_file()].
343 /// ## `resource_path`
344 /// path to resource to play
345 #[doc(alias = "gtk_media_file_set_resource")]
346 fn set_resource(&self, resource_path: Option<&str>) {
347 unsafe {
348 ffi::gtk_media_file_set_resource(
349 self.as_ref().to_glib_none().0,
350 resource_path.to_glib_none().0,
351 );
352 }
353 }
354
355 #[doc(alias = "file")]
356 fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
357 unsafe extern "C" fn notify_file_trampoline<P: IsA<MediaFile>, F: Fn(&P) + 'static>(
358 this: *mut ffi::GtkMediaFile,
359 _param_spec: glib::ffi::gpointer,
360 f: glib::ffi::gpointer,
361 ) {
362 let f: &F = &*(f as *const F);
363 f(MediaFile::from_glib_borrow(this).unsafe_cast_ref())
364 }
365 unsafe {
366 let f: Box_<F> = Box_::new(f);
367 connect_raw(
368 self.as_ptr() as *mut _,
369 b"notify::file\0".as_ptr() as *const _,
370 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
371 notify_file_trampoline::<Self, F> as *const (),
372 )),
373 Box_::into_raw(f),
374 )
375 }
376 }
377
378 #[doc(alias = "input-stream")]
379 fn connect_input_stream_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
380 unsafe extern "C" fn notify_input_stream_trampoline<
381 P: IsA<MediaFile>,
382 F: Fn(&P) + 'static,
383 >(
384 this: *mut ffi::GtkMediaFile,
385 _param_spec: glib::ffi::gpointer,
386 f: glib::ffi::gpointer,
387 ) {
388 let f: &F = &*(f as *const F);
389 f(MediaFile::from_glib_borrow(this).unsafe_cast_ref())
390 }
391 unsafe {
392 let f: Box_<F> = Box_::new(f);
393 connect_raw(
394 self.as_ptr() as *mut _,
395 b"notify::input-stream\0".as_ptr() as *const _,
396 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
397 notify_input_stream_trampoline::<Self, F> as *const (),
398 )),
399 Box_::into_raw(f),
400 )
401 }
402 }
403}
404
405impl<O: IsA<MediaFile>> MediaFileExt for O {}