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