83d2330c54932c7dcaa830d4930ee87de4399918
[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                 NotifyPropertyChanged();
265             }
266         }
267
268         /// <summary>
269         /// The looping status, true or false.
270         /// </summary>
271         /// <since_tizen> 3 </since_tizen>
272         public bool Looping
273         {
274             get
275             {
276                 bool temp = false;
277                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
278                 return temp;
279             }
280             set
281             {
282                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
283                 NotifyPropertyChanged();
284             }
285         }
286
287         /// <summary>
288         /// The mute status, true or false.
289         /// </summary>
290         /// <since_tizen> 3 </since_tizen>
291         public bool Muted
292         {
293             get
294             {
295                 bool temp = false;
296                 GetProperty(VideoView.Property.MUTED).Get(out temp);
297                 return temp;
298             }
299             set
300             {
301                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
302                 NotifyPropertyChanged();
303             }
304         }
305
306         /// <summary>
307         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
308         /// </summary>
309         /// <since_tizen> 3 </since_tizen>
310         public PropertyMap Volume
311         {
312             get
313             {
314                 PropertyMap temp = new PropertyMap();
315                 GetProperty(VideoView.Property.VOLUME).Get(temp);
316                 return temp;
317             }
318             set
319             {
320                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
321                 NotifyPropertyChanged();
322             }
323         }
324
325         /// <summary>
326         /// Video rendering by underlay, true or false.<br />
327         /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
328         /// </summary>
329         /// <since_tizen> 4 </since_tizen>
330         public bool Underlay
331         {
332             get
333             {
334                 bool temp = false;
335                 GetProperty(VideoView.Property.UNDERLAY).Get(out temp);
336                 return temp;
337             }
338             set
339             {
340                 SetProperty(VideoView.Property.UNDERLAY, new PropertyValue(value));
341                 NotifyPropertyChanged();
342             }
343         }
344
345         /// <summary>
346         /// Video file URL as string type.
347         /// </summary>
348         /// <since_tizen> 4 </since_tizen>
349         public string ResourceUrl
350         {
351             get
352             {
353                 string tmp;
354                 GetProperty(VideoView.Property.VIDEO).Get(out tmp);
355                 return tmp;
356             }
357             set
358             {
359                 SetProperty(VideoView.Property.VIDEO, new PropertyValue(value));
360                 NotifyPropertyChanged();
361             }
362         }
363
364     }
365
366 }