1 /**
2 Control for playing video streams.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.videoplayer;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.control;
25 import godot.canvasitem;
26 import godot.node;
27 import godot.videostream;
28 import godot.texture;
29 /**
30 Control for playing video streams.
31 
32 Control node for playing video streams using $(D VideoStream) resources.
33 Supported video formats are $(D url=https://www.webmproject.org/)WebM$(D /url) (`.webm`, $(D VideoStreamWebm)), $(D url=https://www.theora.org/)Ogg Theora$(D /url) (`.ogv`, $(D VideoStreamTheora)), and any format exposed via a GDNative plugin using $(D VideoStreamGDNative).
34 $(B Note:) Due to a bug, VideoPlayer does not support localization remapping yet.
35 $(B Warning:) On HTML5, video playback $(I will) perform poorly due to missing architecture-specific assembly optimizations, especially for VP8/VP9.
36 */
37 @GodotBaseClass struct VideoPlayer
38 {
39 	package(godot) enum string _GODOT_internal_name = "VideoPlayer";
40 public:
41 @nogc nothrow:
42 	union { /** */ godot_object _godot_object; /** */ Control _GODOT_base; }
43 	alias _GODOT_base this;
44 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
45 	package(godot) __gshared bool _classBindingInitialized = false;
46 	package(godot) static struct GDNativeClassBinding
47 	{
48 		__gshared:
49 		@GodotName("get_audio_track") GodotMethod!(long) getAudioTrack;
50 		@GodotName("get_buffering_msec") GodotMethod!(long) getBufferingMsec;
51 		@GodotName("get_bus") GodotMethod!(String) getBus;
52 		@GodotName("get_stream") GodotMethod!(VideoStream) getStream;
53 		@GodotName("get_stream_name") GodotMethod!(String) getStreamName;
54 		@GodotName("get_stream_position") GodotMethod!(double) getStreamPosition;
55 		@GodotName("get_video_texture") GodotMethod!(Texture) getVideoTexture;
56 		@GodotName("get_volume") GodotMethod!(double) getVolume;
57 		@GodotName("get_volume_db") GodotMethod!(double) getVolumeDb;
58 		@GodotName("has_autoplay") GodotMethod!(bool) hasAutoplay;
59 		@GodotName("has_expand") GodotMethod!(bool) hasExpand;
60 		@GodotName("is_paused") GodotMethod!(bool) isPaused;
61 		@GodotName("is_playing") GodotMethod!(bool) isPlaying;
62 		@GodotName("play") GodotMethod!(void) play;
63 		@GodotName("set_audio_track") GodotMethod!(void, long) setAudioTrack;
64 		@GodotName("set_autoplay") GodotMethod!(void, bool) setAutoplay;
65 		@GodotName("set_buffering_msec") GodotMethod!(void, long) setBufferingMsec;
66 		@GodotName("set_bus") GodotMethod!(void, String) setBus;
67 		@GodotName("set_expand") GodotMethod!(void, bool) setExpand;
68 		@GodotName("set_paused") GodotMethod!(void, bool) setPaused;
69 		@GodotName("set_stream") GodotMethod!(void, VideoStream) setStream;
70 		@GodotName("set_stream_position") GodotMethod!(void, double) setStreamPosition;
71 		@GodotName("set_volume") GodotMethod!(void, double) setVolume;
72 		@GodotName("set_volume_db") GodotMethod!(void, double) setVolumeDb;
73 		@GodotName("stop") GodotMethod!(void) stop;
74 	}
75 	/// 
76 	pragma(inline, true) bool opEquals(in VideoPlayer other) const
77 	{ return _godot_object.ptr is other._godot_object.ptr; }
78 	/// 
79 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
80 	{ _godot_object.ptr = n; return null; }
81 	/// 
82 	pragma(inline, true) bool opEquals(typeof(null) n) const
83 	{ return _godot_object.ptr is n; }
84 	/// 
85 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
86 	mixin baseCasts;
87 	/// Construct a new instance of VideoPlayer.
88 	/// Note: use `memnew!VideoPlayer` instead.
89 	static VideoPlayer _new()
90 	{
91 		static godot_class_constructor constructor;
92 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VideoPlayer");
93 		if(constructor is null) return typeof(this).init;
94 		return cast(VideoPlayer)(constructor());
95 	}
96 	@disable new(size_t s);
97 	/**
98 	
99 	*/
100 	long getAudioTrack() const
101 	{
102 		checkClassBinding!(typeof(this))();
103 		return ptrcall!(long)(GDNativeClassBinding.getAudioTrack, _godot_object);
104 	}
105 	/**
106 	
107 	*/
108 	long getBufferingMsec() const
109 	{
110 		checkClassBinding!(typeof(this))();
111 		return ptrcall!(long)(GDNativeClassBinding.getBufferingMsec, _godot_object);
112 	}
113 	/**
114 	
115 	*/
116 	String getBus() const
117 	{
118 		checkClassBinding!(typeof(this))();
119 		return ptrcall!(String)(GDNativeClassBinding.getBus, _godot_object);
120 	}
121 	/**
122 	
123 	*/
124 	Ref!VideoStream getStream() const
125 	{
126 		checkClassBinding!(typeof(this))();
127 		return ptrcall!(VideoStream)(GDNativeClassBinding.getStream, _godot_object);
128 	}
129 	/**
130 	Returns the video stream's name, or `"<No Stream>"` if no video stream is assigned.
131 	*/
132 	String getStreamName() const
133 	{
134 		checkClassBinding!(typeof(this))();
135 		return ptrcall!(String)(GDNativeClassBinding.getStreamName, _godot_object);
136 	}
137 	/**
138 	
139 	*/
140 	double getStreamPosition() const
141 	{
142 		checkClassBinding!(typeof(this))();
143 		return ptrcall!(double)(GDNativeClassBinding.getStreamPosition, _godot_object);
144 	}
145 	/**
146 	Returns the current frame as a $(D Texture).
147 	*/
148 	Ref!Texture getVideoTexture() const
149 	{
150 		checkClassBinding!(typeof(this))();
151 		return ptrcall!(Texture)(GDNativeClassBinding.getVideoTexture, _godot_object);
152 	}
153 	/**
154 	
155 	*/
156 	double getVolume() const
157 	{
158 		checkClassBinding!(typeof(this))();
159 		return ptrcall!(double)(GDNativeClassBinding.getVolume, _godot_object);
160 	}
161 	/**
162 	
163 	*/
164 	double getVolumeDb() const
165 	{
166 		checkClassBinding!(typeof(this))();
167 		return ptrcall!(double)(GDNativeClassBinding.getVolumeDb, _godot_object);
168 	}
169 	/**
170 	
171 	*/
172 	bool hasAutoplay() const
173 	{
174 		checkClassBinding!(typeof(this))();
175 		return ptrcall!(bool)(GDNativeClassBinding.hasAutoplay, _godot_object);
176 	}
177 	/**
178 	
179 	*/
180 	bool hasExpand() const
181 	{
182 		checkClassBinding!(typeof(this))();
183 		return ptrcall!(bool)(GDNativeClassBinding.hasExpand, _godot_object);
184 	}
185 	/**
186 	
187 	*/
188 	bool isPaused() const
189 	{
190 		checkClassBinding!(typeof(this))();
191 		return ptrcall!(bool)(GDNativeClassBinding.isPaused, _godot_object);
192 	}
193 	/**
194 	Returns `true` if the video is playing.
195 	$(B Note:) The video is still considered playing if paused during playback.
196 	*/
197 	bool isPlaying() const
198 	{
199 		checkClassBinding!(typeof(this))();
200 		return ptrcall!(bool)(GDNativeClassBinding.isPlaying, _godot_object);
201 	}
202 	/**
203 	Starts the video playback from the beginning. If the video is paused, this will not unpause the video.
204 	*/
205 	void play()
206 	{
207 		checkClassBinding!(typeof(this))();
208 		ptrcall!(void)(GDNativeClassBinding.play, _godot_object);
209 	}
210 	/**
211 	
212 	*/
213 	void setAudioTrack(in long track)
214 	{
215 		checkClassBinding!(typeof(this))();
216 		ptrcall!(void)(GDNativeClassBinding.setAudioTrack, _godot_object, track);
217 	}
218 	/**
219 	
220 	*/
221 	void setAutoplay(in bool enabled)
222 	{
223 		checkClassBinding!(typeof(this))();
224 		ptrcall!(void)(GDNativeClassBinding.setAutoplay, _godot_object, enabled);
225 	}
226 	/**
227 	
228 	*/
229 	void setBufferingMsec(in long msec)
230 	{
231 		checkClassBinding!(typeof(this))();
232 		ptrcall!(void)(GDNativeClassBinding.setBufferingMsec, _godot_object, msec);
233 	}
234 	/**
235 	
236 	*/
237 	void setBus(in String bus)
238 	{
239 		checkClassBinding!(typeof(this))();
240 		ptrcall!(void)(GDNativeClassBinding.setBus, _godot_object, bus);
241 	}
242 	/**
243 	
244 	*/
245 	void setExpand(in bool enable)
246 	{
247 		checkClassBinding!(typeof(this))();
248 		ptrcall!(void)(GDNativeClassBinding.setExpand, _godot_object, enable);
249 	}
250 	/**
251 	
252 	*/
253 	void setPaused(in bool paused)
254 	{
255 		checkClassBinding!(typeof(this))();
256 		ptrcall!(void)(GDNativeClassBinding.setPaused, _godot_object, paused);
257 	}
258 	/**
259 	
260 	*/
261 	void setStream(VideoStream stream)
262 	{
263 		checkClassBinding!(typeof(this))();
264 		ptrcall!(void)(GDNativeClassBinding.setStream, _godot_object, stream);
265 	}
266 	/**
267 	
268 	*/
269 	void setStreamPosition(in double position)
270 	{
271 		checkClassBinding!(typeof(this))();
272 		ptrcall!(void)(GDNativeClassBinding.setStreamPosition, _godot_object, position);
273 	}
274 	/**
275 	
276 	*/
277 	void setVolume(in double volume)
278 	{
279 		checkClassBinding!(typeof(this))();
280 		ptrcall!(void)(GDNativeClassBinding.setVolume, _godot_object, volume);
281 	}
282 	/**
283 	
284 	*/
285 	void setVolumeDb(in double db)
286 	{
287 		checkClassBinding!(typeof(this))();
288 		ptrcall!(void)(GDNativeClassBinding.setVolumeDb, _godot_object, db);
289 	}
290 	/**
291 	Stops the video playback and sets the stream position to 0.
292 	$(B Note:) Although the stream position will be set to 0, the first frame of the video stream won't become the current frame.
293 	*/
294 	void stop()
295 	{
296 		checkClassBinding!(typeof(this))();
297 		ptrcall!(void)(GDNativeClassBinding.stop, _godot_object);
298 	}
299 	/**
300 	The embedded audio track to play.
301 	*/
302 	@property long audioTrack()
303 	{
304 		return getAudioTrack();
305 	}
306 	/// ditto
307 	@property void audioTrack(long v)
308 	{
309 		setAudioTrack(v);
310 	}
311 	/**
312 	If `true`, playback starts when the scene loads.
313 	*/
314 	@property bool autoplay()
315 	{
316 		return hasAutoplay();
317 	}
318 	/// ditto
319 	@property void autoplay(bool v)
320 	{
321 		setAutoplay(v);
322 	}
323 	/**
324 	Amount of time in milliseconds to store in buffer while playing.
325 	*/
326 	@property long bufferingMsec()
327 	{
328 		return getBufferingMsec();
329 	}
330 	/// ditto
331 	@property void bufferingMsec(long v)
332 	{
333 		setBufferingMsec(v);
334 	}
335 	/**
336 	Audio bus to use for sound playback.
337 	*/
338 	@property String bus()
339 	{
340 		return getBus();
341 	}
342 	/// ditto
343 	@property void bus(String v)
344 	{
345 		setBus(v);
346 	}
347 	/**
348 	If `true`, the video scales to the control size. Otherwise, the control minimum size will be automatically adjusted to match the video stream's dimensions.
349 	*/
350 	@property bool expand()
351 	{
352 		return hasExpand();
353 	}
354 	/// ditto
355 	@property void expand(bool v)
356 	{
357 		setExpand(v);
358 	}
359 	/**
360 	If `true`, the video is paused.
361 	*/
362 	@property bool paused()
363 	{
364 		return isPaused();
365 	}
366 	/// ditto
367 	@property void paused(bool v)
368 	{
369 		setPaused(v);
370 	}
371 	/**
372 	The assigned video stream. See description for supported formats.
373 	*/
374 	@property VideoStream stream()
375 	{
376 		return getStream();
377 	}
378 	/// ditto
379 	@property void stream(VideoStream v)
380 	{
381 		setStream(v);
382 	}
383 	/**
384 	The current position of the stream, in seconds.
385 	$(B Note:) Changing this value won't have any effect as seeking is not implemented yet, except in video formats implemented by a GDNative add-on.
386 	*/
387 	@property double streamPosition()
388 	{
389 		return getStreamPosition();
390 	}
391 	/// ditto
392 	@property void streamPosition(double v)
393 	{
394 		setStreamPosition(v);
395 	}
396 	/**
397 	Audio volume as a linear value.
398 	*/
399 	@property double volume()
400 	{
401 		return getVolume();
402 	}
403 	/// ditto
404 	@property void volume(double v)
405 	{
406 		setVolume(v);
407 	}
408 	/**
409 	Audio volume in dB.
410 	*/
411 	@property double volumeDb()
412 	{
413 		return getVolumeDb();
414 	}
415 	/// ditto
416 	@property void volumeDb(double v)
417 	{
418 		setVolumeDb(v);
419 	}
420 }