[NUI] TCSACR-226 code change (#1032)
[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 global::System.Runtime.InteropServices.HandleRef swigCPtr;
134         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
135         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
136
137         /// <summary>
138         /// Creates an initialized VideoView.
139         /// </summary>
140         /// <since_tizen> 3 </since_tizen>
141         public VideoView() : this(Interop.VideoView.VideoView_New__SWIG_0(), true)
142         {
143             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144         }
145
146         /// <summary>
147         /// Creates an initialized VideoView.<br />
148         /// If the string is empty, VideoView will not display anything.<br />
149         /// </summary>
150         /// <param name="url">The URL of the video resource to display.</param>
151         /// <since_tizen> 3 </since_tizen>
152         public VideoView(string url) : this(Interop.VideoView.VideoView_New__SWIG_1(url), true)
153         {
154             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155         }
156
157         internal VideoView(VideoView videoView) : this(Interop.VideoView.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
158         {
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160         }
161
162         internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VideoView.VideoView_SWIGUpcast(cPtr), cMemoryOwn)
163         {
164             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
165         }
166
167         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
168         private delegate void FinishedCallbackDelegate(IntPtr data);
169
170         /// <summary>
171         /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
172         /// The finished signal is emitted when a video playback has finished.<br />
173         /// </summary>
174         /// <since_tizen> 3 </since_tizen>
175         public event EventHandler<FinishedEventArgs> Finished
176         {
177             add
178             {
179                 if (_videoViewFinishedEventHandler == null)
180                 {
181                     _videoViewFinishedCallbackDelegate = (OnFinished);
182                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
183                 }
184                 _videoViewFinishedEventHandler += value;
185             }
186             remove
187             {
188                 _videoViewFinishedEventHandler -= value;
189                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
190                 {
191                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
192                 }
193             }
194         }
195
196         /// <summary>
197         /// Video file setting type of PropertyMap.
198         /// </summary>
199         /// <since_tizen> 3 </since_tizen>
200         public PropertyMap Video
201         {
202             get
203             {
204                 return (PropertyMap)GetValue(VideoProperty);
205             }
206             set
207             {
208                 SetValue(VideoProperty, value);
209                 NotifyPropertyChanged();
210             }
211         }
212
213         /// <summary>
214         /// The looping status, true or false.
215         /// </summary>
216         /// <since_tizen> 3 </since_tizen>
217         public bool Looping
218         {
219             get
220             {
221                 return (bool)GetValue(LoopingProperty);
222             }
223             set
224             {
225                 SetValue(LoopingProperty, value);
226                 NotifyPropertyChanged();
227             }
228         }
229
230         /// <summary>
231         /// The mute status, true or false.
232         /// </summary>
233         /// <since_tizen> 3 </since_tizen>
234         public bool Muted
235         {
236             get
237             {
238                 return (bool)GetValue(MutedProperty);
239             }
240             set
241             {
242                 SetValue(MutedProperty, value);
243                 NotifyPropertyChanged();
244             }
245         }
246
247         /// <summary>
248         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
249         /// </summary>
250         /// <since_tizen> 3 </since_tizen>
251         public PropertyMap Volume
252         {
253             get
254             {
255                 return (PropertyMap)GetValue(VolumeProperty);
256             }
257             set
258             {
259                 SetValue(VolumeProperty, value);
260                 NotifyPropertyChanged();
261             }
262         }
263
264         /// <summary>
265         /// Video rendering by underlay, true or false.<br />
266         /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
267         /// </summary>
268         /// <since_tizen> 4 </since_tizen>
269         public bool Underlay
270         {
271             get
272             {
273                 return (bool)GetValue(UnderlayProperty);
274             }
275             set
276             {
277                 SetValue(UnderlayProperty, value);
278                 NotifyPropertyChanged();
279             }
280         }
281
282         /// <summary>
283         /// Video file URL as string type.
284         /// </summary>
285         /// <since_tizen> 4 </since_tizen>
286         public string ResourceUrl
287         {
288             get
289             {
290                 return (string)GetValue(ResourceUrlProperty);
291             }
292             set
293             {
294                 SetValue(ResourceUrlProperty, value);
295                 NotifyPropertyChanged();
296             }
297         }
298
299         /// <summary>
300         /// Starts the video playback.
301         /// </summary>
302         /// <since_tizen> 3 </since_tizen>
303         public void Play()
304         {
305             Interop.VideoView.VideoView_Play(swigCPtr);
306             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307         }
308
309         /// <summary>
310         /// Pauses the video playback.
311         /// </summary>
312         /// <since_tizen> 3 </since_tizen>
313         public void Pause()
314         {
315             Interop.VideoView.VideoView_Pause(swigCPtr);
316             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317         }
318
319         /// <summary>
320         /// Stops the video playback.
321         /// </summary>
322         /// <since_tizen> 3 </since_tizen>
323         public void Stop()
324         {
325             Interop.VideoView.VideoView_Stop(swigCPtr);
326             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327         }
328
329         /// <summary>
330         /// Seeks forward by the specified number of milliseconds.
331         /// </summary>
332         /// <param name="millisecond">The position for forward playback.</param>
333         /// <since_tizen> 3 </since_tizen>
334         public void Forward(int millisecond)
335         {
336             Interop.VideoView.VideoView_Forward(swigCPtr, millisecond);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338         }
339
340         /// <summary>
341         /// Seeks backward by the specified number of milliseconds.
342         /// </summary>
343         /// <param name="millisecond">The position for backward playback.</param>
344         /// <since_tizen> 3 </since_tizen>
345         public void Backward(int millisecond)
346         {
347             Interop.VideoView.VideoView_Backward(swigCPtr, millisecond);
348             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349         }
350
351         internal VideoViewSignal FinishedSignal()
352         {
353             VideoViewSignal ret = new VideoViewSignal(Interop.VideoView.VideoView_FinishedSignal(swigCPtr), false);
354             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355             return ret;
356         }
357
358         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VideoView obj)
359         {
360             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
361         }
362
363         /// <summary>
364         /// Dispose.
365         /// </summary>
366         /// <param name="type">DisposeTypes</param>
367         /// <since_tizen> 3 </since_tizen>
368         protected override void Dispose(DisposeTypes type)
369         {
370             if (disposed)
371             {
372                 return;
373             }
374
375             //Release your own unmanaged resources here.
376             //You should not access any managed member here except static instance.
377             //because the execution order of Finalizes is non-deterministic.
378
379             if (this != null && _videoViewFinishedCallbackDelegate != null)
380             {
381                 FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
382             }
383
384             if (swigCPtr.Handle != global::System.IntPtr.Zero)
385             {
386                 if (swigCMemOwn)
387                 {
388                     swigCMemOwn = false;
389                     Interop.VideoView.delete_VideoView(swigCPtr);
390                 }
391                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
392             }
393
394             base.Dispose(type);
395         }
396
397         // Callback for VideoView Finished signal
398         private void OnFinished(IntPtr data)
399         {
400             FinishedEventArgs e = new FinishedEventArgs();
401
402             // Populate all members of "e" (FinishedEventArgs) with real data
403             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
404
405             if (_videoViewFinishedEventHandler != null)
406             {
407                 //here we send all data to user event handlers
408                 _videoViewFinishedEventHandler(this, e);
409             }
410         }
411
412         /// <summary>
413         /// Event arguments that passed via the finished signal.
414         /// </summary>
415         /// <since_tizen> 3 </since_tizen>
416         public class FinishedEventArgs : EventArgs
417         {
418             private VideoView _videoView;
419
420             /// <summary>
421             /// The view for video playback and display.
422             /// </summary>
423             /// <since_tizen> 3 </since_tizen>
424             public VideoView VideoView
425             {
426                 get
427                 {
428                     return _videoView;
429                 }
430                 set
431                 {
432                     _videoView = value;
433                 }
434             }
435         }
436
437         internal new class Property
438         {
439             internal static readonly int VIDEO = Interop.VideoView.VideoView_Property_VIDEO_get();
440             internal static readonly int LOOPING = Interop.VideoView.VideoView_Property_LOOPING_get();
441             internal static readonly int MUTED = Interop.VideoView.VideoView_Property_MUTED_get();
442             internal static readonly int VOLUME = Interop.VideoView.VideoView_Property_VOLUME_get();
443             internal static readonly int UNDERLAY = Interop.VideoView.VideoView_Property_UNDERLAY_get();
444         }
445     }
446 }