Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / VideoView.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI.BaseComponents
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
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         protected override void Dispose(DisposeTypes type)
41         {
42             if(disposed)
43             {
44                 return;
45             }
46
47             if(type == DisposeTypes.Explicit)
48             {
49                 //Called by User
50                 //Release your own managed resources here.
51                 //You should release all of your own disposable objects here.
52             }
53
54             //Release your own unmanaged resources here.
55             //You should not access any managed member here except static instance.
56             //because the execution order of Finalizes is non-deterministic.
57
58             if (swigCPtr.Handle != global::System.IntPtr.Zero)
59             {
60                 if (swigCMemOwn)
61                 {
62                     swigCMemOwn = false;
63                     NDalicPINVOKE.delete_VideoView(swigCPtr);
64                 }
65                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66             }
67
68             base.Dispose(type);
69         }
70
71         /// <summary>
72         /// Event arguments that passed via Finished signal
73         /// </summary>
74         public class FinishedEventArgs : EventArgs
75         {
76             private VideoView _videoView;
77
78             /// <summary>
79             /// The view for video playback and display.
80             /// </summary>
81             public VideoView VideoView
82             {
83                 get
84                 {
85                     return _videoView;
86                 }
87                 set
88                 {
89                     _videoView = value;
90                 }
91             }
92         }
93
94
95         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
96         private delegate void FinishedCallbackDelegate(IntPtr data);
97         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
98         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
99
100
101         /// <summary>
102         /// Event for Finished signal which can be used to subscribe/unsubscribe the event handler
103         /// (in the type of FinishedEventHandler-DaliEventHandler<object,FinishedEventArgs>) provided by the user.<br>
104         /// Finished signal is emitted when a video playback have finished.<br>
105         /// </summary>
106         public event EventHandler<FinishedEventArgs> Finished
107         {
108             add
109             {
110                 if (_videoViewFinishedEventHandler == null)
111                 {
112                     _videoViewFinishedCallbackDelegate = (OnFinished);
113                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
114                 }
115                 _videoViewFinishedEventHandler += value;
116             }
117             remove
118             {
119                 _videoViewFinishedEventHandler -= value;
120                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
121                 {
122                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
123                 }
124             }
125         }
126
127         // Callback for VideoView Finished signal
128         private void OnFinished(IntPtr data)
129         {
130             FinishedEventArgs e = new FinishedEventArgs();
131
132             // Populate all members of "e" (FinishedEventArgs) with real data
133             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
134
135             if (_videoViewFinishedEventHandler != null)
136             {
137                 //here we send all data to user event handlers
138                 _videoViewFinishedEventHandler(this, e);
139             }
140         }
141
142         internal class Property
143         {
144             internal static readonly int VIDEO = NDalicPINVOKE.VideoView_Property_VIDEO_get();
145             internal static readonly int LOOPING = NDalicPINVOKE.VideoView_Property_LOOPING_get();
146             internal static readonly int MUTED = NDalicPINVOKE.VideoView_Property_MUTED_get();
147             internal static readonly int VOLUME = NDalicPINVOKE.VideoView_Property_VOLUME_get();
148         }
149
150         /// <summary>
151         /// Creates an initialized VideoView.
152         /// </summary>
153         public VideoView() : this(NDalicPINVOKE.VideoView_New__SWIG_0(), true)
154         {
155             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156
157         }
158
159         /// <summary>
160         /// Creates an initialized VideoView.<br>
161         /// If the string is empty, VideoView will not display anything.<br>
162         /// </summary>
163         /// <param name="url">The url of the video resource to display</param>
164         public VideoView(string url) : this(NDalicPINVOKE.VideoView_New__SWIG_1(url), true)
165         {
166             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167
168         }
169         internal VideoView(VideoView videoView) : this(NDalicPINVOKE.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
170         {
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172         }
173
174         [Obsolete("Please do not use! this will be deprecated")]
175         public new static VideoView DownCast(BaseHandle handle)
176         {
177             VideoView ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as VideoView;
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179             return ret;
180         }
181
182         /// <summary>
183         /// Starts the video playback.
184         /// </summary>
185         public void Play()
186         {
187             NDalicPINVOKE.VideoView_Play(swigCPtr);
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189         }
190
191         /// <summary>
192         /// Pauses the video playback.
193         /// </summary>
194         public void Pause()
195         {
196             NDalicPINVOKE.VideoView_Pause(swigCPtr);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198         }
199
200         /// <summary>
201         /// Stops the video playback.
202         /// </summary>
203         public void Stop()
204         {
205             NDalicPINVOKE.VideoView_Stop(swigCPtr);
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207         }
208
209         /// <summary>
210         /// Seeks forward by the specified number of milliseconds.
211         /// </summary>
212         /// <param name="millisecond">The position for forward playback</param>
213         public void Forward(int millisecond)
214         {
215             NDalicPINVOKE.VideoView_Forward(swigCPtr, millisecond);
216             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217         }
218
219         /// <summary>
220         /// Seeks backward by the specified number of milliseconds.
221         /// </summary>
222         /// <param name="millisecond">The position for backward playback</param>
223         public void Backward(int millisecond)
224         {
225             NDalicPINVOKE.VideoView_Backward(swigCPtr, millisecond);
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227         }
228
229         internal VideoViewSignal FinishedSignal()
230         {
231             VideoViewSignal ret = new VideoViewSignal(NDalicPINVOKE.VideoView_FinishedSignal(swigCPtr), false);
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233             return ret;
234         }
235
236         /// <summary>
237         /// video file url as string type or PropertyMap.
238         /// </summary>
239         public PropertyMap Video
240         {
241             get
242             {
243                 PropertyMap temp = new PropertyMap();
244                 GetProperty(VideoView.Property.VIDEO).Get(temp);
245                 return temp;
246             }
247             set
248             {
249                 SetProperty(VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue(value));
250             }
251         }
252
253         /// <summary>
254         /// looping status, true or false.
255         /// </summary>
256         public bool Looping
257         {
258             get
259             {
260                 bool temp = false;
261                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
262                 return temp;
263             }
264             set
265             {
266                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
267             }
268         }
269
270         /// <summary>
271         /// mute status, true or false.
272         /// </summary>
273         public bool Muted
274         {
275             get
276             {
277                 bool temp = false;
278                 GetProperty(VideoView.Property.MUTED).Get(out temp);
279                 return temp;
280             }
281             set
282             {
283                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
284             }
285         }
286
287         /// <summary>
288         /// left and right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
289         /// </summary>
290         public PropertyMap Volume
291         {
292             get
293             {
294                 PropertyMap temp = new PropertyMap();
295                 GetProperty(VideoView.Property.VOLUME).Get(temp);
296                 return temp;
297             }
298             set
299             {
300                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
301             }
302         }
303
304     }
305
306 }