Release 4.0.0-preview1-00301
[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
18 namespace Tizen.NUI.BaseComponents
19 {
20
21     using System;
22     using System.Runtime.InteropServices;
23
24     /// <summary>
25     /// VideoView is a control for video playback and display.
26     /// </summary>
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 (_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         public class FinishedEventArgs : EventArgs
86         {
87             private VideoView _videoView;
88
89             /// <summary>
90             /// The view for video playback and display.
91             /// </summary>
92             /// <since_tizen> 3 </since_tizen>
93             public VideoView VideoView
94             {
95                 get
96                 {
97                     return _videoView;
98                 }
99                 set
100                 {
101                     _videoView = value;
102                 }
103             }
104         }
105
106
107         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
108         private delegate void FinishedCallbackDelegate(IntPtr data);
109         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
110         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
111
112
113         /// <summary>
114         /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
115         /// The finished signal is emitted when a video playback has finished.<br />
116         /// </summary>
117         /// <since_tizen> 3 </since_tizen>
118         public event EventHandler<FinishedEventArgs> Finished
119         {
120             add
121             {
122                 if (_videoViewFinishedEventHandler == null)
123                 {
124                     _videoViewFinishedCallbackDelegate = (OnFinished);
125                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
126                 }
127                 _videoViewFinishedEventHandler += value;
128             }
129             remove
130             {
131                 _videoViewFinishedEventHandler -= value;
132                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
133                 {
134                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
135                 }
136             }
137         }
138
139         // Callback for VideoView Finished signal
140         private void OnFinished(IntPtr data)
141         {
142             FinishedEventArgs e = new FinishedEventArgs();
143
144             // Populate all members of "e" (FinishedEventArgs) with real data
145             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
146
147             if (_videoViewFinishedEventHandler != null)
148             {
149                 //here we send all data to user event handlers
150                 _videoViewFinishedEventHandler(this, e);
151             }
152         }
153
154         internal new class Property
155         {
156             internal static readonly int VIDEO = NDalicPINVOKE.VideoView_Property_VIDEO_get();
157             internal static readonly int LOOPING = NDalicPINVOKE.VideoView_Property_LOOPING_get();
158             internal static readonly int MUTED = NDalicPINVOKE.VideoView_Property_MUTED_get();
159             internal static readonly int VOLUME = NDalicPINVOKE.VideoView_Property_VOLUME_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         /// [Obsolete("Please do not use! this will be deprecated")]
190         /// </summary>
191         /// <param name="handle"></param>
192         /// <returns></returns>
193         [Obsolete("Please do not use! this will be deprecated")]
194         public new static VideoView DownCast(BaseHandle handle)
195         {
196             VideoView ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as VideoView;
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198             return ret;
199         }
200
201         /// <summary>
202         /// Starts the video playback.
203         /// </summary>
204         /// <since_tizen> 3 </since_tizen>
205         public void Play()
206         {
207             NDalicPINVOKE.VideoView_Play(swigCPtr);
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209         }
210
211         /// <summary>
212         /// Pauses the video playback.
213         /// </summary>
214         /// <since_tizen> 3 </since_tizen>
215         public void Pause()
216         {
217             NDalicPINVOKE.VideoView_Pause(swigCPtr);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219         }
220
221         /// <summary>
222         /// Stops the video playback.
223         /// </summary>
224         /// <since_tizen> 3 </since_tizen>
225         public void Stop()
226         {
227             NDalicPINVOKE.VideoView_Stop(swigCPtr);
228             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229         }
230
231         /// <summary>
232         /// Seeks forward by the specified number of milliseconds.
233         /// </summary>
234         /// <param name="millisecond">The position for forward playback.</param>
235         /// <since_tizen> 3 </since_tizen>
236         public void Forward(int millisecond)
237         {
238             NDalicPINVOKE.VideoView_Forward(swigCPtr, millisecond);
239             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240         }
241
242         /// <summary>
243         /// Seeks backward by the specified number of milliseconds.
244         /// </summary>
245         /// <param name="millisecond">The position for backward playback.</param>
246         /// <since_tizen> 3 </since_tizen>
247         public void Backward(int millisecond)
248         {
249             NDalicPINVOKE.VideoView_Backward(swigCPtr, millisecond);
250             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251         }
252
253         internal VideoViewSignal FinishedSignal()
254         {
255             VideoViewSignal ret = new VideoViewSignal(NDalicPINVOKE.VideoView_FinishedSignal(swigCPtr), false);
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257             return ret;
258         }
259
260         /// <summary>
261         /// Video file URL as string type or PropertyMap.
262         /// </summary>
263         /// <since_tizen> 3 </since_tizen>
264         public PropertyMap Video
265         {
266             get
267             {
268                 PropertyMap temp = new PropertyMap();
269                 GetProperty(VideoView.Property.VIDEO).Get(temp);
270                 return temp;
271             }
272             set
273             {
274                 SetProperty(VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue(value));
275             }
276         }
277
278         /// <summary>
279         /// The looping status, true or false.
280         /// </summary>
281         /// <since_tizen> 3 </since_tizen>
282         public bool Looping
283         {
284             get
285             {
286                 bool temp = false;
287                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
288                 return temp;
289             }
290             set
291             {
292                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
293             }
294         }
295
296         /// <summary>
297         /// The mute status, true or false.
298         /// </summary>
299         /// <since_tizen> 3 </since_tizen>
300         public bool Muted
301         {
302             get
303             {
304                 bool temp = false;
305                 GetProperty(VideoView.Property.MUTED).Get(out temp);
306                 return temp;
307             }
308             set
309             {
310                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
311             }
312         }
313
314         /// <summary>
315         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
316         /// </summary>
317         /// <since_tizen> 3 </since_tizen>
318         public PropertyMap Volume
319         {
320             get
321             {
322                 PropertyMap temp = new PropertyMap();
323                 GetProperty(VideoView.Property.VOLUME).Get(temp);
324                 return temp;
325             }
326             set
327             {
328                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
329             }
330         }
331
332     }
333
334 }