Merge "[Context] Modified default result size"
[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 (_videoViewFinishedCallbackDelegate != null)
59             {
60                 FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
61             }
62
63             if (swigCPtr.Handle != global::System.IntPtr.Zero)
64             {
65                 if (swigCMemOwn)
66                 {
67                     swigCMemOwn = false;
68                     NDalicPINVOKE.delete_VideoView(swigCPtr);
69                 }
70                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
71             }
72
73             base.Dispose(type);
74         }
75
76         /// <summary>
77         /// Event arguments that passed via the finished signal.
78         /// </summary>
79         public class FinishedEventArgs : EventArgs
80         {
81             private VideoView _videoView;
82
83             /// <summary>
84             /// The view for video playback and display.
85             /// </summary>
86             public VideoView VideoView
87             {
88                 get
89                 {
90                     return _videoView;
91                 }
92                 set
93                 {
94                     _videoView = value;
95                 }
96             }
97         }
98
99
100         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
101         private delegate void FinishedCallbackDelegate(IntPtr data);
102         private EventHandler<FinishedEventArgs> _videoViewFinishedEventHandler;
103         private FinishedCallbackDelegate _videoViewFinishedCallbackDelegate;
104
105
106         /// <summary>
107         /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
108         /// (in the type of FinishedEventHandler-DaliEventHandler<object,FinishedEventArgs>) provided by the user.<br>
109         /// The finished signal is emitted when a video playback has finished.<br>
110         /// </summary>
111         public event EventHandler<FinishedEventArgs> Finished
112         {
113             add
114             {
115                 if (_videoViewFinishedEventHandler == null)
116                 {
117                     _videoViewFinishedCallbackDelegate = (OnFinished);
118                     FinishedSignal().Connect(_videoViewFinishedCallbackDelegate);
119                 }
120                 _videoViewFinishedEventHandler += value;
121             }
122             remove
123             {
124                 _videoViewFinishedEventHandler -= value;
125                 if (_videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
126                 {
127                     FinishedSignal().Disconnect(_videoViewFinishedCallbackDelegate);
128                 }
129             }
130         }
131
132         // Callback for VideoView Finished signal
133         private void OnFinished(IntPtr data)
134         {
135             FinishedEventArgs e = new FinishedEventArgs();
136
137             // Populate all members of "e" (FinishedEventArgs) with real data
138             e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
139
140             if (_videoViewFinishedEventHandler != null)
141             {
142                 //here we send all data to user event handlers
143                 _videoViewFinishedEventHandler(this, e);
144             }
145         }
146
147         internal new class Property
148         {
149             internal static readonly int VIDEO = NDalicPINVOKE.VideoView_Property_VIDEO_get();
150             internal static readonly int LOOPING = NDalicPINVOKE.VideoView_Property_LOOPING_get();
151             internal static readonly int MUTED = NDalicPINVOKE.VideoView_Property_MUTED_get();
152             internal static readonly int VOLUME = NDalicPINVOKE.VideoView_Property_VOLUME_get();
153         }
154
155         /// <summary>
156         /// Creates an initialized VideoView.
157         /// </summary>
158         public VideoView() : this(NDalicPINVOKE.VideoView_New__SWIG_0(), true)
159         {
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161
162         }
163
164         /// <summary>
165         /// Creates an initialized VideoView.<br>
166         /// If the string is empty, VideoView will not display anything.<br>
167         /// </summary>
168         /// <param name="url">The URL of the video resource to display.</param>
169         public VideoView(string url) : this(NDalicPINVOKE.VideoView_New__SWIG_1(url), true)
170         {
171             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172
173         }
174         internal VideoView(VideoView videoView) : this(NDalicPINVOKE.new_VideoView__SWIG_1(VideoView.getCPtr(videoView)), true)
175         {
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177         }
178
179         [Obsolete("Please do not use! this will be deprecated")]
180         public new static VideoView DownCast(BaseHandle handle)
181         {
182             VideoView ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as VideoView;
183             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184             return ret;
185         }
186
187         /// <summary>
188         /// Starts the video playback.
189         /// </summary>
190         public void Play()
191         {
192             NDalicPINVOKE.VideoView_Play(swigCPtr);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194         }
195
196         /// <summary>
197         /// Pauses the video playback.
198         /// </summary>
199         public void Pause()
200         {
201             NDalicPINVOKE.VideoView_Pause(swigCPtr);
202             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203         }
204
205         /// <summary>
206         /// Stops the video playback.
207         /// </summary>
208         public void Stop()
209         {
210             NDalicPINVOKE.VideoView_Stop(swigCPtr);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212         }
213
214         /// <summary>
215         /// Seeks forward by the specified number of milliseconds.
216         /// </summary>
217         /// <param name="millisecond">The position for forward playback.</param>
218         public void Forward(int millisecond)
219         {
220             NDalicPINVOKE.VideoView_Forward(swigCPtr, millisecond);
221             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222         }
223
224         /// <summary>
225         /// Seeks backward by the specified number of milliseconds.
226         /// </summary>
227         /// <param name="millisecond">The position for backward playback.</param>
228         public void Backward(int millisecond)
229         {
230             NDalicPINVOKE.VideoView_Backward(swigCPtr, millisecond);
231             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232         }
233
234         internal VideoViewSignal FinishedSignal()
235         {
236             VideoViewSignal ret = new VideoViewSignal(NDalicPINVOKE.VideoView_FinishedSignal(swigCPtr), false);
237             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238             return ret;
239         }
240
241         /// <summary>
242         /// Video file URL as string type or PropertyMap.
243         /// </summary>
244         public PropertyMap Video
245         {
246             get
247             {
248                 PropertyMap temp = new PropertyMap();
249                 GetProperty(VideoView.Property.VIDEO).Get(temp);
250                 return temp;
251             }
252             set
253             {
254                 SetProperty(VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue(value));
255             }
256         }
257
258         /// <summary>
259         /// The looping status, true or false.
260         /// </summary>
261         public bool Looping
262         {
263             get
264             {
265                 bool temp = false;
266                 GetProperty(VideoView.Property.LOOPING).Get(out temp);
267                 return temp;
268             }
269             set
270             {
271                 SetProperty(VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue(value));
272             }
273         }
274
275         /// <summary>
276         /// The mute status, true or false.
277         /// </summary>
278         public bool Muted
279         {
280             get
281             {
282                 bool temp = false;
283                 GetProperty(VideoView.Property.MUTED).Get(out temp);
284                 return temp;
285             }
286             set
287             {
288                 SetProperty(VideoView.Property.MUTED, new Tizen.NUI.PropertyValue(value));
289             }
290         }
291
292         /// <summary>
293         /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
294         /// </summary>
295         public PropertyMap Volume
296         {
297             get
298             {
299                 PropertyMap temp = new PropertyMap();
300                 GetProperty(VideoView.Property.VOLUME).Get(temp);
301                 return temp;
302             }
303             set
304             {
305                 SetProperty(VideoView.Property.VOLUME, new PropertyValue(value));
306             }
307         }
308
309     }
310
311 }