[Tizen] Ensuring that Registry.Unregister is called from the most derived class befor...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / VideoView.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI.BaseComponents
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22
23     /// <summary>
24     /// VideoView is a control for video playback and display.
25     /// </summary>
26     public class VideoView : View
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.VideoView_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VideoView obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         protected override void Dispose(DisposeTypes type)
41         {
42             if(disposed)
43             {
44                 return;
45             }
46
47             if(type == DisposeTypes.Explicit)
48             {
49                 //Called by User
50                 //Release your own managed resources here.
51                 //You should release all of your own disposable objects here.
52             }
53
54             //Release your own unmanaged resources here.
55             //You should not access any managed member here except static instance.
56             //because the execution order of Finalizes is non-deterministic.
57
58             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63
64                     //Unreference this instance from Registry.
65                     Registry.Unregister(this);
66
67                     NDalicPINVOKE.delete_VideoView(swigCPtr);
68                 }
69                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
70             }
71
72             base.Dispose(type);
73         }
74
75         /// <summary>
76         /// Event arguments that passed via Finished signal
77         /// </summary>
78         public class FinishedEventArgs : EventArgs
79         {
80             private VideoView _videoView;
81
82             /// <summary>
83             /// The view for video playback and display.
84             /// </summary>
85             public VideoView VideoView
86             {
87                 get
88                 {
89                     return _videoView;
90                 }
91                 set
92                 {
93                     _videoView = value;
94                 }
95             }
96         }
97
98
99         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
100         private delegate void FinishedCallbackDelegate(IntPtr data);
101         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
102         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
103
104
105         /// <summary>
106         /// Event for Finished signal which can be used to subscribe/unsubscribe the event handler
107         /// (in the type of FinishedEventHandler-DaliEventHandler<object,FinishedEventArgs>) provided by the user.<br>
108         /// Finished signal is emitted when a video playback have finished.<br>
109         /// </summary>
110         public event EventHandler<FinishedEventArgs> Finished
111         {
112             add
113             {
114                 if (_videoViewFinishedEventHandler == null)
115                 {
116                     _videoViewFinishedCallbackDelegate = (OnFinished);
117                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
118                 }
119                 _videoViewFinishedEventHandler += value;
120             }
121             remove
122             {
123                 _videoViewFinishedEventHandler -= value;
124                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
125                 {
126                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
127                 }
128             }
129         }
130
131         // Callback for VideoView Finished signal
132         private void OnFinished(IntPtr data)
133         {
134             FinishedEventArgs e = new FinishedEventArgs();
135
136             // Populate all members of "e" (FinishedEventArgs) with real data
137             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
138
139             if (_videoViewFinishedEventHandler != null)
140             {
141                 //here we send all data to user event handlers
142                 _videoViewFinishedEventHandler(this, e);
143             }
144         }
145
146         internal class Property
147         {
148             internal static readonly int VIDEO = NDalicPINVOKE.VideoView_Property_VIDEO_get();
149             internal static readonly int LOOPING = NDalicPINVOKE.VideoView_Property_LOOPING_get();
150             internal static readonly int MUTED = NDalicPINVOKE.VideoView_Property_MUTED_get();
151             internal static readonly int VOLUME = NDalicPINVOKE.VideoView_Property_VOLUME_get();
152         }
153
154         /// <summary>
155         /// Creates an initialized VideoView.
156         /// </summary>
157         public VideoView() : this(NDalicPINVOKE.VideoView_New__SWIG_0(), true)
158         {
159             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
160
161         }
162
163         /// <summary>
164         /// Creates an initialized VideoView.<br>
165         /// If the string is empty, VideoView will not display anything.<br>
166         /// </summary>
167         /// <param name="url">The url of the video resource to display</param>
168         public VideoView(string url) : this(NDalicPINVOKE.VideoView_New__SWIG_1(url), true)
169         {
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171
172         }
173         internal VideoView(VideoView videoView) : this(NDalicPINVOKE.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
174         {
175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176         }
177
178         [Obsolete("Please do not use! this will be deprecated")]
179         public new static VideoView DownCast(BaseHandle handle)
180         {
181             VideoView ret = new VideoView(NDalicPINVOKE.VideoView_DownCast(BaseHandle.getCPtr(handle)), true);
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183             return ret;
184         }
185
186         /// <summary>
187         /// Starts the video playback.
188         /// </summary>
189         public void Play()
190         {
191             NDalicPINVOKE.VideoView_Play(swigCPtr);
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193         }
194
195         /// <summary>
196         /// Pauses the video playback.
197         /// </summary>
198         public void Pause()
199         {
200             NDalicPINVOKE.VideoView_Pause(swigCPtr);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202         }
203
204         /// <summary>
205         /// Stops the video playback.
206         /// </summary>
207         public void Stop()
208         {
209             NDalicPINVOKE.VideoView_Stop(swigCPtr);
210             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
211         }
212
213         /// <summary>
214         /// Seeks forward by the specified number of milliseconds.
215         /// </summary>
216         /// <param name="millisecond">The position for forward playback</param>
217         public void Forward(int millisecond)
218         {
219             NDalicPINVOKE.VideoView_Forward(swigCPtr, millisecond);
220             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221         }
222
223         /// <summary>
224         /// Seeks backward by the specified number of milliseconds.
225         /// </summary>
226         /// <param name="millisecond">The position for backward playback</param>
227         public void Backward(int millisecond)
228         {
229             NDalicPINVOKE.VideoView_Backward(swigCPtr, millisecond);
230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231         }
232
233         internal VideoViewSignal FinishedSignal()
234         {
235             VideoViewSignal ret = new VideoViewSignal(NDalicPINVOKE.VideoView_FinishedSignal(swigCPtr), false);
236             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237             return ret;
238         }
239
240         /// <summary>
241         /// video file url as string type or PropertyMap.
242         /// </summary>
243         public PropertyMap Video
244         {
245             get
246             {
247                 PropertyMap temp = new PropertyMap();
248                 GetProperty(VideoView.Property.VIDEO).Get(temp);
249                 return temp;
250             }
251             set
252             {
253                 SetProperty(VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue(value));
254             }
255         }
256
257         /// <summary>
258         /// looping status, true or false.
259         /// </summary>
260         public bool Looping
261         {
262             get
263             {
264                 bool temp = false;
265                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
266                 return temp;
267             }
268             set
269             {
270                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
271             }
272         }
273
274         /// <summary>
275         /// mute status, true or false.
276         /// </summary>
277         public bool Muted
278         {
279             get
280             {
281                 bool temp = false;
282                 GetProperty(VideoView.Property.MUTED).Get(out temp);
283                 return temp;
284             }
285             set
286             {
287                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
288             }
289         }
290
291         /// <summary>
292         /// left and right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
293         /// </summary>
294         public PropertyMap Volume
295         {
296             get
297             {
298                 PropertyMap temp = new PropertyMap();
299                 GetProperty(VideoView.Property.VOLUME).Get(temp);
300                 return temp;
301             }
302             set
303             {
304                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
305             }
306         }
307
308     }
309
310 }