e7c415d642a29a0f53b2fb5c84d4e6524e6c97ee
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / VideoView.cs
1 /*
2  * Copyright(c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 using System;
18 using System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24     /// <summary>
25     /// VideoView is a control for video playback and display.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class VideoView : View
29     {
30         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public static readonly BindableProperty VideoProperty = BindableProperty.Create("Video", typeof(PropertyMap), typeof(VideoView), null, propertyChanged: (bindable, oldValue, newValue) =>
33         {
34             var videoView = (VideoView)bindable;
35             if (newValue != null)
36             {
37                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
38             }
39         },
40         defaultValueCreator: (bindable) =>
41         {
42             var videoView = (VideoView)bindable;
43             PropertyMap temp = new PropertyMap();
44             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.VIDEO).Get(temp);
45             return temp;
46         });
47         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
48         [EditorBrowsable(EditorBrowsableState.Never)]
49         public static readonly BindableProperty LoopingProperty = BindableProperty.Create("Looping", typeof(bool), typeof(VideoView), false, propertyChanged: (bindable, oldValue, newValue) =>
50         {
51             var videoView = (VideoView)bindable;
52             if (newValue != null)
53             {
54                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue((bool)newValue));
55             }
56         },
57         defaultValueCreator: (bindable) =>
58         {
59             var videoView = (VideoView)bindable;
60             bool temp = false;
61             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.LOOPING).Get(out temp);
62             return temp;
63         });
64         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
65         [EditorBrowsable(EditorBrowsableState.Never)]
66         public static readonly BindableProperty MutedProperty = BindableProperty.Create("Muted", typeof(bool), typeof(VideoView), false, propertyChanged: (bindable, oldValue, newValue) =>
67         {
68             var videoView = (VideoView)bindable;
69             if (newValue != null)
70             {
71                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.MUTED, new Tizen.NUI.PropertyValue((bool)newValue));
72             }
73         },
74         defaultValueCreator: (bindable) =>
75         {
76             var videoView = (VideoView)bindable;
77             bool temp = false;
78             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.MUTED).Get(out temp);
79             return temp;
80         });
81         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public static readonly BindableProperty VolumeProperty = BindableProperty.Create("Volume", typeof(PropertyMap), typeof(VideoView), null, propertyChanged: (bindable, oldValue, newValue) =>
84         {
85             var videoView = (VideoView)bindable;
86             if (newValue != null)
87             {
88                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.VOLUME, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
89             }
90         },
91         defaultValueCreator: (bindable) =>
92         {
93             var videoView = (VideoView)bindable;
94             PropertyMap temp = new PropertyMap();
95             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.VOLUME).Get(temp);
96             return temp;
97         });
98         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
99         [EditorBrowsable(EditorBrowsableState.Never)]
100         public static readonly BindableProperty UnderlayProperty = BindableProperty.Create("Underlay", typeof(bool), typeof(VideoView), false, propertyChanged: (bindable, oldValue, newValue) =>
101         {
102             var videoView = (VideoView)bindable;
103             if (newValue != null)
104             {
105                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.UNDERLAY, new Tizen.NUI.PropertyValue((bool)newValue));
106             }
107         },
108         defaultValueCreator: (bindable) =>
109         {
110             var videoView = (VideoView)bindable;
111             bool temp = false;
112             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.UNDERLAY).Get(out temp);
113             return temp;
114         });
115         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
116         [EditorBrowsable(EditorBrowsableState.Never)]
117         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create("ResourceUrl", typeof(string), typeof(VideoView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
118         {
119             var videoView = (VideoView)bindable;
120             if (newValue != null)
121             {
122                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((string)newValue));
123             }
124         },
125         defaultValueCreator: (bindable) =>
126         {
127             var videoView = (VideoView)bindable;
128             string temp;
129             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.VIDEO).Get(out temp);
130             return temp;
131         });
132
133         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
134         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
135
136         /// <summary>
137         /// Creates an initialized VideoView.
138         /// </summary>
139         /// <since_tizen> 3 </since_tizen>
140         public VideoView() : this(Interop.VideoView.VideoView_New__SWIG_0(), true)
141         {
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143         }
144
145         /// <summary>
146         /// Creates an initialized VideoView.<br />
147         /// If the string is empty, VideoView will not display anything.<br />
148         /// </summary>
149         /// <param name="url">The URL of the video resource to display.</param>
150         /// <since_tizen> 3 </since_tizen>
151         public VideoView(string url) : this(Interop.VideoView.VideoView_New__SWIG_1(url), true)
152         {
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154         }
155
156         /// <summary>
157         /// Creates an initialized VideoView.<br />
158         /// If the string is empty, VideoView will not display anything.<br />
159         /// </summary>
160         /// <param name="swCodec">Video rendering by H/W codec if false.</param>
161         [EditorBrowsable(EditorBrowsableState.Never)]
162         public VideoView(bool swCodec) : this(Interop.VideoView.VideoView_New__SWIG_2(swCodec), true)
163         {
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165         }
166
167         /// <summary>
168         /// Creates an initialized VideoView.<br />
169         /// If the string is empty, VideoView will not display anything.<br />
170         /// </summary>
171         /// <param name="url">The URL of the video resource to display.</param>
172         /// <param name="swCodec">Video rendering by H/W codec if false.</param>
173         [EditorBrowsable(EditorBrowsableState.Never)]
174         public VideoView(string url, bool swCodec) : this(Interop.VideoView.VideoView_New__SWIG_3(url, swCodec), true)
175         {
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177         }
178
179         internal VideoView(VideoView videoView) : this(Interop.VideoView.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
180         {
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182         }
183
184         internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VideoView.VideoView_SWIGUpcast(cPtr), cMemoryOwn)
185         {
186         }
187
188         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
189         private delegate void FinishedCallbackDelegate(IntPtr data);
190
191         /// <summary>
192         /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
193         /// The finished signal is emitted when a video playback has finished.<br />
194         /// </summary>
195         /// <since_tizen> 3 </since_tizen>
196         public event EventHandler<FinishedEventArgs> Finished
197         {
198             add
199             {
200                 if (_videoViewFinishedEventHandler == null)
201                 {
202                     _videoViewFinishedCallbackDelegate = (OnFinished);
203                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
204                 }
205                 _videoViewFinishedEventHandler += value;
206             }
207             remove
208             {
209                 _videoViewFinishedEventHandler -= value;
210                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
211                 {
212                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
213                 }
214             }
215         }
216
217         /// <summary>
218         /// Video file setting type of PropertyMap.
219         /// </summary>
220         /// <since_tizen> 3 </since_tizen>
221         public PropertyMap Video
222         {
223             get
224             {
225                 return (PropertyMap)GetValue(VideoProperty);
226             }
227             set
228             {
229                 SetValue(VideoProperty, value);
230                 NotifyPropertyChanged();
231             }
232         }
233
234         /// <summary>
235         /// The looping status, true or false.
236         /// </summary>
237         /// <since_tizen> 3 </since_tizen>
238         public bool Looping
239         {
240             get
241             {
242                 return (bool)GetValue(LoopingProperty);
243             }
244             set
245             {
246                 SetValue(LoopingProperty, value);
247                 NotifyPropertyChanged();
248             }
249         }
250
251         /// <summary>
252         /// The mute status, true or false.
253         /// </summary>
254         /// <since_tizen> 3 </since_tizen>
255         public bool Muted
256         {
257             get
258             {
259                 return (bool)GetValue(MutedProperty);
260             }
261             set
262             {
263                 SetValue(MutedProperty, value);
264                 NotifyPropertyChanged();
265             }
266         }
267
268         /// <summary>
269         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
270         /// </summary>
271         /// <since_tizen> 3 </since_tizen>
272         public PropertyMap Volume
273         {
274             get
275             {
276                 return (PropertyMap)GetValue(VolumeProperty);
277             }
278             set
279             {
280                 SetValue(VolumeProperty, value);
281                 NotifyPropertyChanged();
282             }
283         }
284
285         /// <summary>
286         /// Video rendering by underlay, true or false.<br />
287         /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
288         /// </summary>
289         /// <since_tizen> 4 </since_tizen>
290         public bool Underlay
291         {
292             get
293             {
294                 return (bool)GetValue(UnderlayProperty);
295             }
296             set
297             {
298                 SetValue(UnderlayProperty, value);
299                 NotifyPropertyChanged();
300             }
301         }
302
303         /// <summary>
304         /// Video file URL as string type.
305         /// </summary>
306         /// <since_tizen> 4 </since_tizen>
307         public string ResourceUrl
308         {
309             get
310             {
311                 return (string)GetValue(ResourceUrlProperty);
312             }
313             set
314             {
315                 SetValue(ResourceUrlProperty, value);
316                 NotifyPropertyChanged();
317             }
318         }
319
320         /// <summary>
321         /// Starts the video playback.
322         /// </summary>
323         /// <since_tizen> 3 </since_tizen>
324         public void Play()
325         {
326             Interop.VideoView.VideoView_Play(swigCPtr);
327             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328         }
329
330         /// <summary>
331         /// Pauses the video playback.
332         /// </summary>
333         /// <since_tizen> 3 </since_tizen>
334         public void Pause()
335         {
336             Interop.VideoView.VideoView_Pause(swigCPtr);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338         }
339
340         /// <summary>
341         /// Stops the video playback.
342         /// </summary>
343         /// <since_tizen> 3 </since_tizen>
344         public void Stop()
345         {
346             Interop.VideoView.VideoView_Stop(swigCPtr);
347             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348         }
349
350         /// <summary>
351         /// Seeks forward by the specified number of milliseconds.
352         /// </summary>
353         /// <param name="millisecond">The position for forward playback.</param>
354         /// <since_tizen> 3 </since_tizen>
355         public void Forward(int millisecond)
356         {
357             Interop.VideoView.VideoView_Forward(swigCPtr, millisecond);
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359         }
360
361         /// <summary>
362         /// Seeks backward by the specified number of milliseconds.
363         /// </summary>
364         /// <param name="millisecond">The position for backward playback.</param>
365         /// <since_tizen> 3 </since_tizen>
366         public void Backward(int millisecond)
367         {
368             Interop.VideoView.VideoView_Backward(swigCPtr, millisecond);
369             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370         }
371
372         internal VideoViewSignal FinishedSignal()
373         {
374             VideoViewSignal ret = new VideoViewSignal(Interop.VideoView.VideoView_FinishedSignal(swigCPtr), false);
375             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376             return ret;
377         }
378
379         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VideoView obj)
380         {
381             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
382         }
383
384         /// <summary>
385         /// Dispose.
386         /// </summary>
387         /// <param name="type">DisposeTypes</param>
388         /// <since_tizen> 3 </since_tizen>
389         protected override void Dispose(DisposeTypes type)
390         {
391             if (disposed)
392             {
393                 return;
394             }
395
396             //Release your own unmanaged resources here.
397             //You should not access any managed member here except static instance.
398             //because the execution order of Finalizes is non-deterministic.
399
400             if (this != null && _videoViewFinishedCallbackDelegate != null)
401             {
402                 FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
403             }
404
405             base.Dispose(type);
406         }
407
408         /// This will not be public opened.
409         [EditorBrowsable(EditorBrowsableState.Never)]
410         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
411         {
412             Interop.VideoView.delete_VideoView(swigCPtr);
413         }
414
415         // Callback for VideoView Finished signal
416         private void OnFinished(IntPtr data)
417         {
418             FinishedEventArgs e = new FinishedEventArgs();
419
420             // Populate all members of "e" (FinishedEventArgs) with real data
421             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
422
423             if (_videoViewFinishedEventHandler != null)
424             {
425                 //here we send all data to user event handlers
426                 _videoViewFinishedEventHandler(this, e);
427             }
428         }
429
430         /// <summary>
431         /// Event arguments that passed via the finished signal.
432         /// </summary>
433         /// <since_tizen> 3 </since_tizen>
434         public class FinishedEventArgs : EventArgs
435         {
436             private VideoView _videoView;
437
438             /// <summary>
439             /// The view for video playback and display.
440             /// </summary>
441             /// <since_tizen> 3 </since_tizen>
442             public VideoView VideoView
443             {
444                 get
445                 {
446                     return _videoView;
447                 }
448                 set
449                 {
450                     _videoView = value;
451                 }
452             }
453         }
454
455         internal new class Property
456         {
457             internal static readonly int VIDEO = Interop.VideoView.VideoView_Property_VIDEO_get();
458             internal static readonly int LOOPING = Interop.VideoView.VideoView_Property_LOOPING_get();
459             internal static readonly int MUTED = Interop.VideoView.VideoView_Property_MUTED_get();
460             internal static readonly int VOLUME = Interop.VideoView.VideoView_Property_VOLUME_get();
461             internal static readonly int UNDERLAY = Interop.VideoView.VideoView_Property_UNDERLAY_get();
462         }
463     }
464 }