[NUI] Add protect codes in Dispose()
[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
21 namespace Tizen.NUI.BaseComponents
22 {
23     /// <summary>
24     /// VideoView is a control for video playback and display.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class VideoView : View
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30
31         internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.VideoView_SWIGUpcast(cPtr), cMemoryOwn)
32         {
33             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34         }
35
36         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VideoView obj)
37         {
38             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39         }
40
41         /// <summary>
42         /// Dispose.
43         /// </summary>
44         /// <param name="type">DisposeTypes</param>
45         /// <since_tizen> 3 </since_tizen>
46         protected override void Dispose(DisposeTypes type)
47         {
48             if(disposed)
49             {
50                 return;
51             }
52
53             if(type == DisposeTypes.Explicit)
54             {
55                 //Called by User
56                 //Release your own managed resources here.
57                 //You should release all of your own disposable objects here.
58             }
59
60             //Release your own unmanaged resources here.
61             //You should not access any managed member here except static instance.
62             //because the execution order of Finalizes is non-deterministic.
63
64             if (this != null && _videoViewFinishedCallbackDelegate != null)
65             {
66                 FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
67             }
68
69             if (swigCPtr.Handle != global::System.IntPtr.Zero)
70             {
71                 if (swigCMemOwn)
72                 {
73                     swigCMemOwn = false;
74                     NDalicPINVOKE.delete_VideoView(swigCPtr);
75                 }
76                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
77             }
78
79             base.Dispose(type);
80         }
81
82         /// <summary>
83         /// Event arguments that passed via the finished signal.
84         /// </summary>
85         /// <since_tizen> 3 </since_tizen>
86         public class FinishedEventArgs : EventArgs
87         {
88             private VideoView _videoView;
89
90             /// <summary>
91             /// The view for video playback and display.
92             /// </summary>
93             /// <since_tizen> 3 </since_tizen>
94             public VideoView VideoView
95             {
96                 get
97                 {
98                     return _videoView;
99                 }
100                 set
101                 {
102                     _videoView = value;
103                 }
104             }
105         }
106
107
108         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
109         private delegate void FinishedCallbackDelegate(IntPtr data);
110         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
111         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
112
113
114         /// <summary>
115         /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
116         /// The finished signal is emitted when a video playback has finished.<br />
117         /// </summary>
118         /// <since_tizen> 3 </since_tizen>
119         public event EventHandler<FinishedEventArgs> Finished
120         {
121             add
122             {
123                 if (_videoViewFinishedEventHandler == null)
124                 {
125                     _videoViewFinishedCallbackDelegate = (OnFinished);
126                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
127                 }
128                 _videoViewFinishedEventHandler += value;
129             }
130             remove
131             {
132                 _videoViewFinishedEventHandler -= value;
133                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
134                 {
135                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
136                 }
137             }
138         }
139
140         // Callback for VideoView Finished signal
141         private void OnFinished(IntPtr data)
142         {
143             FinishedEventArgs e = new FinishedEventArgs();
144
145             // Populate all members of "e" (FinishedEventArgs) with real data
146             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
147
148             if (_videoViewFinishedEventHandler != null)
149             {
150                 //here we send all data to user event handlers
151                 _videoViewFinishedEventHandler(this, e);
152             }
153         }
154
155         internal new class Property
156         {
157             internal static readonly int VIDEO = NDalicPINVOKE.VideoView_Property_VIDEO_get();
158             internal static readonly int LOOPING = NDalicPINVOKE.VideoView_Property_LOOPING_get();
159             internal static readonly int MUTED = NDalicPINVOKE.VideoView_Property_MUTED_get();
160             internal static readonly int VOLUME = NDalicPINVOKE.VideoView_Property_VOLUME_get();
161             internal static readonly int UNDERLAY = NDalicPINVOKE.VideoView_Property_UNDERLAY_get();
162         }
163
164         /// <summary>
165         /// Creates an initialized VideoView.
166         /// </summary>
167         /// <since_tizen> 3 </since_tizen>
168         public VideoView() : this(NDalicPINVOKE.VideoView_New__SWIG_0(), true)
169         {
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171
172         }
173
174         /// <summary>
175         /// Creates an initialized VideoView.<br />
176         /// If the string is empty, VideoView will not display anything.<br />
177         /// </summary>
178         /// <param name="url">The URL of the video resource to display.</param>
179         /// <since_tizen> 3 </since_tizen>
180         public VideoView(string url) : this(NDalicPINVOKE.VideoView_New__SWIG_1(url), true)
181         {
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183
184         }
185         internal VideoView(VideoView videoView) : this(NDalicPINVOKE.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
186         {
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188         }
189
190         /// <summary>
191         /// Starts the video playback.
192         /// </summary>
193         /// <since_tizen> 3 </since_tizen>
194         public void Play()
195         {
196             NDalicPINVOKE.VideoView_Play(swigCPtr);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198         }
199
200         /// <summary>
201         /// Pauses the video playback.
202         /// </summary>
203         /// <since_tizen> 3 </since_tizen>
204         public void Pause()
205         {
206             NDalicPINVOKE.VideoView_Pause(swigCPtr);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208         }
209
210         /// <summary>
211         /// Stops the video playback.
212         /// </summary>
213         /// <since_tizen> 3 </since_tizen>
214         public void Stop()
215         {
216             NDalicPINVOKE.VideoView_Stop(swigCPtr);
217             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218         }
219
220         /// <summary>
221         /// Seeks forward by the specified number of milliseconds.
222         /// </summary>
223         /// <param name="millisecond">The position for forward playback.</param>
224         /// <since_tizen> 3 </since_tizen>
225         public void Forward(int millisecond)
226         {
227             NDalicPINVOKE.VideoView_Forward(swigCPtr, millisecond);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229         }
230
231         /// <summary>
232         /// Seeks backward by the specified number of milliseconds.
233         /// </summary>
234         /// <param name="millisecond">The position for backward playback.</param>
235         /// <since_tizen> 3 </since_tizen>
236         public void Backward(int millisecond)
237         {
238             NDalicPINVOKE.VideoView_Backward(swigCPtr, millisecond);
239             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240         }
241
242         internal VideoViewSignal FinishedSignal()
243         {
244             VideoViewSignal ret = new VideoViewSignal(NDalicPINVOKE.VideoView_FinishedSignal(swigCPtr), false);
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246             return ret;
247         }
248
249         /// <summary>
250         /// Video file setting type of PropertyMap.
251         /// </summary>
252         /// <since_tizen> 3 </since_tizen>
253         public PropertyMap Video
254         {
255             get
256             {
257                 PropertyMap temp = new PropertyMap();
258                 GetProperty(VideoView.Property.VIDEO).Get(temp);
259                 return temp;
260             }
261             set
262             {
263                 SetProperty(VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue(value));
264             }
265         }
266
267         /// <summary>
268         /// The looping status, true or false.
269         /// </summary>
270         /// <since_tizen> 3 </since_tizen>
271         public bool Looping
272         {
273             get
274             {
275                 bool temp = false;
276                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
277                 return temp;
278             }
279             set
280             {
281                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
282             }
283         }
284
285         /// <summary>
286         /// The mute status, true or false.
287         /// </summary>
288         /// <since_tizen> 3 </since_tizen>
289         public bool Muted
290         {
291             get
292             {
293                 bool temp = false;
294                 GetProperty(VideoView.Property.MUTED).Get(out temp);
295                 return temp;
296             }
297             set
298             {
299                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
300             }
301         }
302
303         /// <summary>
304         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
305         /// </summary>
306         /// <since_tizen> 3 </since_tizen>
307         public PropertyMap Volume
308         {
309             get
310             {
311                 PropertyMap temp = new PropertyMap();
312                 GetProperty(VideoView.Property.VOLUME).Get(temp);
313                 return temp;
314             }
315             set
316             {
317                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
318             }
319         }
320
321         /// <summary>
322         /// Video rendering by underlay, true or false.<br />
323         /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
324         /// </summary>
325         /// <since_tizen> 4 </since_tizen>
326         public bool Underlay
327         {
328             get
329             {
330                 bool temp = false;
331                 GetProperty(VideoView.Property.UNDERLAY).Get(out temp);
332                 return temp;
333             }
334             set
335             {
336                 SetProperty(VideoView.Property.UNDERLAY, new PropertyValue(value));
337             }
338         }
339
340         /// <summary>
341         /// Video file URL as string type.
342         /// </summary>
343         /// <since_tizen> 4 </since_tizen>
344         public string ResourceUrl
345         {
346             get
347             {
348                 string tmp;
349                 GetProperty(VideoView.Property.VIDEO).Get(out tmp);
350                 return tmp;
351             }
352             set
353             {
354                 SetProperty(VideoView.Property.VIDEO, new PropertyValue(value));
355             }
356         }
357
358     }
359
360 }