1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.MediaFile;
26 
27 private import gio.FileIF;
28 private import gio.InputStream;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import gobject.ObjectG;
32 private import gtk.MediaStream;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 
36 
37 /**
38  * `GtkMediaFile` implements `GtkMediaStream` for files.
39  * 
40  * This provides a simple way to play back video files with GTK.
41  * 
42  * GTK provides a GIO extension point for `GtkMediaFile` implementations
43  * to allow for external implementations using various media frameworks.
44  * 
45  * GTK itself includes implementations using GStreamer and ffmpeg.
46  */
47 public class MediaFile : MediaStream
48 {
49 	/** the main Gtk struct */
50 	protected GtkMediaFile* gtkMediaFile;
51 
52 	/** Get the main Gtk struct */
53 	public GtkMediaFile* getMediaFileStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gtkMediaFile;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gtkMediaFile;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GtkMediaFile* gtkMediaFile, bool ownedRef = false)
70 	{
71 		this.gtkMediaFile = gtkMediaFile;
72 		super(cast(GtkMediaStream*)gtkMediaFile, ownedRef);
73 	}
74 
75 
76 	/** */
77 	public static GType getType()
78 	{
79 		return gtk_media_file_get_type();
80 	}
81 
82 	/**
83 	 * Creates a new empty media file.
84 	 *
85 	 * Returns: a new `GtkMediaFile`
86 	 *
87 	 * Throws: ConstructionException GTK+ fails to create the object.
88 	 */
89 	public this()
90 	{
91 		auto __p = gtk_media_file_new();
92 
93 		if(__p is null)
94 		{
95 			throw new ConstructionException("null returned by new");
96 		}
97 
98 		this(cast(GtkMediaFile*) __p, true);
99 	}
100 
101 	/**
102 	 * Creates a new media file to play @file.
103 	 *
104 	 * Params:
105 	 *     file = The file to play
106 	 *
107 	 * Returns: a new `GtkMediaFile` playing @file
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(FileIF file)
112 	{
113 		auto __p = gtk_media_file_new_for_file((file is null) ? null : file.getFileStruct());
114 
115 		if(__p is null)
116 		{
117 			throw new ConstructionException("null returned by new_for_file");
118 		}
119 
120 		this(cast(GtkMediaFile*) __p, true);
121 	}
122 
123 	/**
124 	 * Creates a new media file for the given filename.
125 	 *
126 	 * This is a utility function that converts the given @filename
127 	 * to a `GFile` and calls [ctor@Gtk.MediaFile.new_for_file].
128 	 *
129 	 * Params:
130 	 *     filename = filename to open
131 	 *
132 	 * Returns: a new `GtkMediaFile` playing @filename
133 	 *
134 	 * Throws: ConstructionException GTK+ fails to create the object.
135 	 */
136 	public this(string filename)
137 	{
138 		auto __p = gtk_media_file_new_for_filename(Str.toStringz(filename));
139 
140 		if(__p is null)
141 		{
142 			throw new ConstructionException("null returned by new_for_filename");
143 		}
144 
145 		this(cast(GtkMediaFile*) __p, true);
146 	}
147 
148 	/**
149 	 * Creates a new media file to play @stream.
150 	 *
151 	 * If you want the resulting media to be seekable,
152 	 * the stream should implement the `GSeekable` interface.
153 	 *
154 	 * Params:
155 	 *     stream = The stream to play
156 	 *
157 	 * Returns: a new `GtkMediaFile`
158 	 *
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this(InputStream stream)
162 	{
163 		auto __p = gtk_media_file_new_for_input_stream((stream is null) ? null : stream.getInputStreamStruct());
164 
165 		if(__p is null)
166 		{
167 			throw new ConstructionException("null returned by new_for_input_stream");
168 		}
169 
170 		this(cast(GtkMediaFile*) __p, true);
171 	}
172 
173 	/**
174 	 * Resets the media file to be empty.
175 	 */
176 	public void clear()
177 	{
178 		gtk_media_file_clear(gtkMediaFile);
179 	}
180 
181 	/**
182 	 * Returns the file that @self is currently playing from.
183 	 *
184 	 * When @self is not playing or not playing from a file,
185 	 * %NULL is returned.
186 	 *
187 	 * Returns: The currently playing file
188 	 *     or %NULL if not playing from a file.
189 	 */
190 	public FileIF getFile()
191 	{
192 		auto __p = gtk_media_file_get_file(gtkMediaFile);
193 
194 		if(__p is null)
195 		{
196 			return null;
197 		}
198 
199 		return ObjectG.getDObject!(FileIF)(cast(GFile*) __p);
200 	}
201 
202 	/**
203 	 * Returns the stream that @self is currently playing from.
204 	 *
205 	 * When @self is not playing or not playing from a stream,
206 	 * %NULL is returned.
207 	 *
208 	 * Returns: The currently playing
209 	 *     stream or %NULL if not playing from a stream.
210 	 */
211 	public InputStream getInputStream()
212 	{
213 		auto __p = gtk_media_file_get_input_stream(gtkMediaFile);
214 
215 		if(__p is null)
216 		{
217 			return null;
218 		}
219 
220 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p);
221 	}
222 
223 	/**
224 	 * Sets the `GtkMediaFile` to play the given file.
225 	 *
226 	 * If any file is still playing, stop playing it.
227 	 *
228 	 * Params:
229 	 *     file = the file to play
230 	 */
231 	public void setFile(FileIF file)
232 	{
233 		gtk_media_file_set_file(gtkMediaFile, (file is null) ? null : file.getFileStruct());
234 	}
235 
236 	/**
237 	 * Sets the `GtkMediaFile to play the given file.
238 	 *
239 	 * This is a utility function that converts the given @filename
240 	 * to a `GFile` and calls [method@Gtk.MediaFile.set_file].
241 	 *
242 	 * Params:
243 	 *     filename = name of file to play
244 	 */
245 	public void setFilename(string filename)
246 	{
247 		gtk_media_file_set_filename(gtkMediaFile, Str.toStringz(filename));
248 	}
249 
250 	/**
251 	 * Sets the `GtkMediaFile` to play the given stream.
252 	 *
253 	 * If anything is still playing, stop playing it.
254 	 *
255 	 * Full control about the @stream is assumed for the duration of
256 	 * playback. The stream will not be closed.
257 	 *
258 	 * Params:
259 	 *     stream = the stream to play from
260 	 */
261 	public void setInputStream(InputStream stream)
262 	{
263 		gtk_media_file_set_input_stream(gtkMediaFile, (stream is null) ? null : stream.getInputStreamStruct());
264 	}
265 
266 	/**
267 	 * Sets the `GtkMediaFile to play the given resource.
268 	 *
269 	 * This is a utility function that converts the given @resource_path
270 	 * to a `GFile` and calls [method@Gtk.MediaFile.set_file].
271 	 *
272 	 * Params:
273 	 *     resourcePath = path to resource to play
274 	 */
275 	public void setResource(string resourcePath)
276 	{
277 		gtk_media_file_set_resource(gtkMediaFile, Str.toStringz(resourcePath));
278 	}
279 }