Merge "Changed internal property to public-api and added public-api"
[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             internal static readonly int UNDERLAY = NDalicPINVOKE.VideoView_Property_UNDERLAY_get();
161         }
162
163         /// <summary>
164         /// Creates an initialized VideoView.
165         /// </summary>
166         /// <since_tizen> 3 </since_tizen>
167         public VideoView() : this(NDalicPINVOKE.VideoView_New__SWIG_0(), true)
168         {
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170
171         }
172
173         /// <summary>
174         /// Creates an initialized VideoView.<br />
175         /// If the string is empty, VideoView will not display anything.<br />
176         /// </summary>
177         /// <param name="url">The URL of the video resource to display.</param>
178         /// <since_tizen> 3 </since_tizen>
179         public VideoView(string url) : this(NDalicPINVOKE.VideoView_New__SWIG_1(url), true)
180         {
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182
183         }
184         internal VideoView(VideoView videoView) : this(NDalicPINVOKE.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
185         {
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187         }
188
189         /// <summary>
190         /// [Obsolete("Please do not use! this will be deprecated")]
191         /// </summary>
192         /// <param name="handle"></param>
193         /// <returns></returns>
194         [Obsolete("Please do not use! this will be deprecated")]
195         public new static VideoView DownCast(BaseHandle handle)
196         {
197             VideoView ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as VideoView;
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         /// <summary>
203         /// Starts the video playback.
204         /// </summary>
205         /// <since_tizen> 3 </since_tizen>
206         public void Play()
207         {
208             NDalicPINVOKE.VideoView_Play(swigCPtr);
209             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210         }
211
212         /// <summary>
213         /// Pauses the video playback.
214         /// </summary>
215         /// <since_tizen> 3 </since_tizen>
216         public void Pause()
217         {
218             NDalicPINVOKE.VideoView_Pause(swigCPtr);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220         }
221
222         /// <summary>
223         /// Stops the video playback.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public void Stop()
227         {
228             NDalicPINVOKE.VideoView_Stop(swigCPtr);
229             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230         }
231
232         /// <summary>
233         /// Seeks forward by the specified number of milliseconds.
234         /// </summary>
235         /// <param name="millisecond">The position for forward playback.</param>
236         /// <since_tizen> 3 </since_tizen>
237         public void Forward(int millisecond)
238         {
239             NDalicPINVOKE.VideoView_Forward(swigCPtr, millisecond);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241         }
242
243         /// <summary>
244         /// Seeks backward by the specified number of milliseconds.
245         /// </summary>
246         /// <param name="millisecond">The position for backward playback.</param>
247         /// <since_tizen> 3 </since_tizen>
248         public void Backward(int millisecond)
249         {
250             NDalicPINVOKE.VideoView_Backward(swigCPtr, millisecond);
251             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252         }
253
254         internal VideoViewSignal FinishedSignal()
255         {
256             VideoViewSignal ret = new VideoViewSignal(NDalicPINVOKE.VideoView_FinishedSignal(swigCPtr), false);
257             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258             return ret;
259         }
260
261         /// <summary>
262         /// Video file URL as string type or PropertyMap.
263         /// </summary>
264         /// <since_tizen> 3 </since_tizen>
265         public PropertyMap Video
266         {
267             get
268             {
269                 PropertyMap temp = new PropertyMap();
270                 GetProperty(VideoView.Property.VIDEO).Get(temp);
271                 return temp;
272             }
273             set
274             {
275                 SetProperty(VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue(value));
276             }
277         }
278
279         /// <summary>
280         /// The looping status, true or false.
281         /// </summary>
282         /// <since_tizen> 3 </since_tizen>
283         public bool Looping
284         {
285             get
286             {
287                 bool temp = false;
288                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
289                 return temp;
290             }
291             set
292             {
293                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
294             }
295         }
296
297         /// <summary>
298         /// The mute status, true or false.
299         /// </summary>
300         /// <since_tizen> 3 </since_tizen>
301         public bool Muted
302         {
303             get
304             {
305                 bool temp = false;
306                 GetProperty(VideoView.Property.MUTED).Get(out temp);
307                 return temp;
308             }
309             set
310             {
311                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
312             }
313         }
314
315         /// <summary>
316         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
317         /// </summary>
318         /// <since_tizen> 3 </since_tizen>
319         public PropertyMap Volume
320         {
321             get
322             {
323                 PropertyMap temp = new PropertyMap();
324                 GetProperty(VideoView.Property.VOLUME).Get(temp);
325                 return temp;
326             }
327             set
328             {
329                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
330             }
331         }
332
333         /// <summary>
334         /// Video rendering by underlay, true or false.<br />
335         /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
336         /// </summary>
337         /// <since_tizen> 4 </since_tizen>
338         public bool Underlay
339         {
340             get
341             {
342                 bool temp = false;
343                 GetProperty(VideoView.Property.UNDERLAY).Get(out temp);
344                 return temp;
345             }
346             set
347             {
348                 SetProperty(VideoView.Property.UNDERLAY, new PropertyValue(value));
349             }
350         }
351
352     }
353
354 }