572ac5dc78b0085999a9649ef113048f4fe199fa
[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 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24     /// <summary>
25     /// VideoView is a control for video playback and display.
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public class VideoView : View
29     {
30         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public static readonly BindableProperty VideoProperty = BindableProperty.Create("Video", typeof(PropertyMap), typeof(VideoView), null, propertyChanged: (bindable, oldValue, newValue) =>
33         {
34             var videoView = (VideoView)bindable;
35             if (newValue != null)
36             {
37                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
38             }
39         },
40         defaultValueCreator: (bindable) =>
41         {
42             var videoView = (VideoView)bindable;
43             PropertyMap temp = new PropertyMap();
44             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.VIDEO).Get(temp);
45             return temp;
46         });
47         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
48         [EditorBrowsable(EditorBrowsableState.Never)]
49         public static readonly BindableProperty LoopingProperty = BindableProperty.Create("Looping", typeof(bool), typeof(VideoView), false, propertyChanged: (bindable, oldValue, newValue) =>
50         {
51             var videoView = (VideoView)bindable;
52             if (newValue != null)
53             {
54                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue((bool)newValue));
55             }
56         },
57         defaultValueCreator: (bindable) =>
58         {
59             var videoView = (VideoView)bindable;
60             bool temp = false;
61             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.LOOPING).Get(out temp);
62             return temp;
63         });
64         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
65         [EditorBrowsable(EditorBrowsableState.Never)]
66         public static readonly BindableProperty MutedProperty = BindableProperty.Create("Muted", typeof(bool), typeof(VideoView), false, propertyChanged: (bindable, oldValue, newValue) =>
67         {
68             var videoView = (VideoView)bindable;
69             if (newValue != null)
70             {
71                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.MUTED, new Tizen.NUI.PropertyValue((bool)newValue));
72             }
73         },
74         defaultValueCreator: (bindable) =>
75         {
76             var videoView = (VideoView)bindable;
77             bool temp = false;
78             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.MUTED).Get(out temp);
79             return temp;
80         });
81         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
82         [EditorBrowsable(EditorBrowsableState.Never)]
83         public static readonly BindableProperty VolumeProperty = BindableProperty.Create("Volume", typeof(PropertyMap), typeof(VideoView), null, propertyChanged: (bindable, oldValue, newValue) =>
84         {
85             var videoView = (VideoView)bindable;
86             if (newValue != null)
87             {
88                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.VOLUME, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
89             }
90         },
91         defaultValueCreator: (bindable) =>
92         {
93             var videoView = (VideoView)bindable;
94             PropertyMap temp = new PropertyMap();
95             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.VOLUME).Get(temp);
96             return temp;
97         });
98         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
99         [EditorBrowsable(EditorBrowsableState.Never)]
100         public static readonly BindableProperty UnderlayProperty = BindableProperty.Create("Underlay", typeof(bool), typeof(VideoView), false, propertyChanged: (bindable, oldValue, newValue) =>
101         {
102             var videoView = (VideoView)bindable;
103             if (newValue != null)
104             {
105                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.UNDERLAY, new Tizen.NUI.PropertyValue((bool)newValue));
106             }
107         },
108         defaultValueCreator: (bindable) =>
109         {
110             var videoView = (VideoView)bindable;
111             bool temp = false;
112             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.UNDERLAY).Get(out temp);
113             return temp;
114         });
115         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
116         [EditorBrowsable(EditorBrowsableState.Never)]
117         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create("ResourceUrl", typeof(string), typeof(VideoView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
118         {
119             var videoView = (VideoView)bindable;
120             if (newValue != null)
121             {
122                 Tizen.NUI.Object.SetProperty(videoView.swigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((string)newValue));
123             }
124         },
125         defaultValueCreator: (bindable) =>
126         {
127             var videoView = (VideoView)bindable;
128             string temp;
129             Tizen.NUI.Object.GetProperty(videoView.swigCPtr, VideoView.Property.VIDEO).Get(out temp);
130             return temp;
131         });
132
133         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
134         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
135
136         /// <summary>
137         /// Creates an initialized VideoView.
138         /// </summary>
139         /// <since_tizen> 3 </since_tizen>
140         public VideoView() : this(Interop.VideoView.VideoView_New__SWIG_0(), true)
141         {
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143         }
144
145         /// <summary>
146         /// Creates an initialized VideoView.<br />
147         /// If the string is empty, VideoView will not display anything.<br />
148         /// </summary>
149         /// <param name="url">The URL of the video resource to display.</param>
150         /// <since_tizen> 3 </since_tizen>
151         public VideoView(string url) : this(Interop.VideoView.VideoView_New__SWIG_1(url), true)
152         {
153             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154         }
155
156         internal VideoView(VideoView videoView) : this(Interop.VideoView.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
157         {
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159         }
160
161         internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.VideoView.VideoView_SWIGUpcast(cPtr), cMemoryOwn)
162         {
163         }
164
165         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
166         private delegate void FinishedCallbackDelegate(IntPtr data);
167
168         /// <summary>
169         /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
170         /// The finished signal is emitted when a video playback has finished.<br />
171         /// </summary>
172         /// <since_tizen> 3 </since_tizen>
173         public event EventHandler<FinishedEventArgs> Finished
174         {
175             add
176             {
177                 if (_videoViewFinishedEventHandler == null)
178                 {
179                     _videoViewFinishedCallbackDelegate = (OnFinished);
180                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
181                 }
182                 _videoViewFinishedEventHandler += value;
183             }
184             remove
185             {
186                 _videoViewFinishedEventHandler -= value;
187                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
188                 {
189                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
190                 }
191             }
192         }
193
194         /// <summary>
195         /// Video file setting type of PropertyMap.
196         /// </summary>
197         /// <since_tizen> 3 </since_tizen>
198         public PropertyMap Video
199         {
200             get
201             {
202                 return (PropertyMap)GetValue(VideoProperty);
203             }
204             set
205             {
206                 SetValue(VideoProperty, value);
207                 NotifyPropertyChanged();
208             }
209         }
210
211         /// <summary>
212         /// The looping status, true or false.
213         /// </summary>
214         /// <since_tizen> 3 </since_tizen>
215         public bool Looping
216         {
217             get
218             {
219                 return (bool)GetValue(LoopingProperty);
220             }
221             set
222             {
223                 SetValue(LoopingProperty, value);
224                 NotifyPropertyChanged();
225             }
226         }
227
228         /// <summary>
229         /// The mute status, true or false.
230         /// </summary>
231         /// <since_tizen> 3 </since_tizen>
232         public bool Muted
233         {
234             get
235             {
236                 return (bool)GetValue(MutedProperty);
237             }
238             set
239             {
240                 SetValue(MutedProperty, value);
241                 NotifyPropertyChanged();
242             }
243         }
244
245         /// <summary>
246         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
247         /// </summary>
248         /// <since_tizen> 3 </since_tizen>
249         public PropertyMap Volume
250         {
251             get
252             {
253                 return (PropertyMap)GetValue(VolumeProperty);
254             }
255             set
256             {
257                 SetValue(VolumeProperty, value);
258                 NotifyPropertyChanged();
259             }
260         }
261
262         /// <summary>
263         /// Video rendering by underlay, true or false.<br />
264         /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
265         /// </summary>
266         /// <since_tizen> 4 </since_tizen>
267         public bool Underlay
268         {
269             get
270             {
271                 return (bool)GetValue(UnderlayProperty);
272             }
273             set
274             {
275                 SetValue(UnderlayProperty, value);
276                 NotifyPropertyChanged();
277             }
278         }
279
280         /// <summary>
281         /// Video file URL as string type.
282         /// </summary>
283         /// <since_tizen> 4 </since_tizen>
284         public string ResourceUrl
285         {
286             get
287             {
288                 return (string)GetValue(ResourceUrlProperty);
289             }
290             set
291             {
292                 SetValue(ResourceUrlProperty, value);
293                 NotifyPropertyChanged();
294             }
295         }
296
297         /// <summary>
298         /// Starts the video playback.
299         /// </summary>
300         /// <since_tizen> 3 </since_tizen>
301         public void Play()
302         {
303             Interop.VideoView.VideoView_Play(swigCPtr);
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305         }
306
307         /// <summary>
308         /// Pauses the video playback.
309         /// </summary>
310         /// <since_tizen> 3 </since_tizen>
311         public void Pause()
312         {
313             Interop.VideoView.VideoView_Pause(swigCPtr);
314             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315         }
316
317         /// <summary>
318         /// Stops the video playback.
319         /// </summary>
320         /// <since_tizen> 3 </since_tizen>
321         public void Stop()
322         {
323             Interop.VideoView.VideoView_Stop(swigCPtr);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325         }
326
327         /// <summary>
328         /// Seeks forward by the specified number of milliseconds.
329         /// </summary>
330         /// <param name="millisecond">The position for forward playback.</param>
331         /// <since_tizen> 3 </since_tizen>
332         public void Forward(int millisecond)
333         {
334             Interop.VideoView.VideoView_Forward(swigCPtr, millisecond);
335             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336         }
337
338         /// <summary>
339         /// Seeks backward by the specified number of milliseconds.
340         /// </summary>
341         /// <param name="millisecond">The position for backward playback.</param>
342         /// <since_tizen> 3 </since_tizen>
343         public void Backward(int millisecond)
344         {
345             Interop.VideoView.VideoView_Backward(swigCPtr, millisecond);
346             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347         }
348
349         internal VideoViewSignal FinishedSignal()
350         {
351             VideoViewSignal ret = new VideoViewSignal(Interop.VideoView.VideoView_FinishedSignal(swigCPtr), false);
352             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353             return ret;
354         }
355
356         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VideoView obj)
357         {
358             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
359         }
360
361         /// <summary>
362         /// Dispose.
363         /// </summary>
364         /// <param name="type">DisposeTypes</param>
365         /// <since_tizen> 3 </since_tizen>
366         protected override void Dispose(DisposeTypes type)
367         {
368             if (disposed)
369             {
370                 return;
371             }
372
373             //Release your own unmanaged resources here.
374             //You should not access any managed member here except static instance.
375             //because the execution order of Finalizes is non-deterministic.
376
377             if (this != null && _videoViewFinishedCallbackDelegate != null)
378             {
379                 FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
380             }
381
382             base.Dispose(type);
383         }
384
385         /// This will not be public opened.
386         [EditorBrowsable(EditorBrowsableState.Never)]
387         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
388         {
389             Interop.VideoView.delete_VideoView(swigCPtr);
390         }
391
392         // Callback for VideoView Finished signal
393         private void OnFinished(IntPtr data)
394         {
395             FinishedEventArgs e = new FinishedEventArgs();
396
397             // Populate all members of "e" (FinishedEventArgs) with real data
398             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
399
400             if (_videoViewFinishedEventHandler != null)
401             {
402                 //here we send all data to user event handlers
403                 _videoViewFinishedEventHandler(this, e);
404             }
405         }
406
407         /// <summary>
408         /// Event arguments that passed via the finished signal.
409         /// </summary>
410         /// <since_tizen> 3 </since_tizen>
411         public class FinishedEventArgs : EventArgs
412         {
413             private VideoView _videoView;
414
415             /// <summary>
416             /// The view for video playback and display.
417             /// </summary>
418             /// <since_tizen> 3 </since_tizen>
419             public VideoView VideoView
420             {
421                 get
422                 {
423                     return _videoView;
424                 }
425                 set
426                 {
427                     _videoView = value;
428                 }
429             }
430         }
431
432         internal new class Property
433         {
434             internal static readonly int VIDEO = Interop.VideoView.VideoView_Property_VIDEO_get();
435             internal static readonly int LOOPING = Interop.VideoView.VideoView_Property_LOOPING_get();
436             internal static readonly int MUTED = Interop.VideoView.VideoView_Property_MUTED_get();
437             internal static readonly int VOLUME = Interop.VideoView.VideoView_Property_VOLUME_get();
438             internal static readonly int UNDERLAY = Interop.VideoView.VideoView_Property_UNDERLAY_get();
439         }
440     }
441 }