2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.Binding;
22 namespace Tizen.NUI.BaseComponents
25 /// VideoView is a control for video playback and display.
27 /// <since_tizen> 3 </since_tizen>
28 public class VideoView : View
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(nameof(Video), typeof(PropertyMap), typeof(VideoView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
34 var videoView = (VideoView)bindable;
37 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
40 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
42 var videoView = (VideoView)bindable;
43 PropertyMap temp = new PropertyMap();
44 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO).Get(temp);
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(nameof(Looping), typeof(bool), typeof(VideoView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
51 var videoView = (VideoView)bindable;
54 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue((bool)newValue));
57 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
59 var videoView = (VideoView)bindable;
61 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.LOOPING).Get(out temp);
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(nameof(Muted), typeof(bool), typeof(VideoView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
68 var videoView = (VideoView)bindable;
71 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.MUTED, new Tizen.NUI.PropertyValue((bool)newValue));
74 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
76 var videoView = (VideoView)bindable;
78 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.MUTED).Get(out temp);
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(nameof(Volume), typeof(PropertyMap), typeof(VideoView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
85 var videoView = (VideoView)bindable;
88 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VOLUME, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
91 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
93 var videoView = (VideoView)bindable;
94 PropertyMap temp = new PropertyMap();
95 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VOLUME).Get(temp);
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(nameof(Underlay), typeof(bool), typeof(VideoView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
102 var videoView = (VideoView)bindable;
103 if (newValue != null)
105 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.UNDERLAY, new Tizen.NUI.PropertyValue((bool)newValue));
108 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
110 var videoView = (VideoView)bindable;
112 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.UNDERLAY).Get(out temp);
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(nameof(ResourceUrl), typeof(string), typeof(VideoView), string.Empty, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
119 var videoView = (VideoView)bindable;
120 if (newValue != null)
122 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((string)newValue));
125 defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
127 var videoView = (VideoView)bindable;
129 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO).Get(out temp);
133 private FinishedCallbackDelegate videoViewFinishedCallbackDelegate;
134 private EventHandler<FinishedEventArgs> videoViewFinishedEventHandler;
137 /// Creates an initialized VideoView.
139 /// <since_tizen> 3 </since_tizen>
140 public VideoView() : this(Interop.VideoView.New(), true)
142 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 /// Creates an initialized VideoView.<br />
147 /// If the string is empty, VideoView will not display anything.<br />
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.New(url), true)
153 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// Creates an initialized VideoView.<br />
158 /// If the string is empty, VideoView will not display anything.<br />
160 /// <param name="swCodec">Video rendering by H/W codec if false.</param>
161 [EditorBrowsable(EditorBrowsableState.Never)]
162 public VideoView(bool swCodec) : this(Interop.VideoView.New(swCodec), true)
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 /// Creates an initialized VideoView.<br />
169 /// If the string is empty, VideoView will not display anything.<br />
171 /// <param name="url">The URL of the video resource to display.</param>
172 /// <param name="swCodec">Video rendering by H/W codec if false.</param>
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public VideoView(string url, bool swCodec) : this(Interop.VideoView.New(url, swCodec), true)
176 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// Hidden API (Inhouse API).
181 /// Using Uri class to provide safe service and secure API.
182 /// Creates an initialized VideoView.
183 /// If the string is empty, VideoView will not display anything.
185 /// <param name="uri">The URI of the video resource to display.</param>
186 /// <param name="swCodec">Video rendering by H/W codec if false.</param>
187 [EditorBrowsable(EditorBrowsableState.Never)]
188 public VideoView(Uri uri, bool swCodec) : this(Interop.VideoView.New((uri == null) ? String.Empty : uri.AbsoluteUri, swCodec), true)
190 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 internal VideoView(VideoView videoView) : this(Interop.VideoView.NewVideoView(VideoView.getCPtr(videoView)), true)
195 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
202 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
203 private delegate void FinishedCallbackDelegate(IntPtr data);
206 /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
207 /// The finished signal is emitted when a video playback has finished.<br />
209 /// <since_tizen> 3 </since_tizen>
210 public event EventHandler<FinishedEventArgs> Finished
214 if (videoViewFinishedEventHandler == null)
216 videoViewFinishedCallbackDelegate = (OnFinished);
217 FinishedSignal().Connect(videoViewFinishedCallbackDelegate);
219 videoViewFinishedEventHandler += value;
223 videoViewFinishedEventHandler -= value;
224 if (videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
226 FinishedSignal().Disconnect(videoViewFinishedCallbackDelegate);
232 /// Video file setting type of PropertyMap.
234 /// <since_tizen> 3 </since_tizen>
235 public PropertyMap Video
239 return (PropertyMap)GetValue(VideoProperty);
243 SetValue(VideoProperty, value);
244 NotifyPropertyChanged();
249 /// The looping status, true or false.
251 /// <since_tizen> 3 </since_tizen>
256 return (bool)GetValue(LoopingProperty);
260 SetValue(LoopingProperty, value);
261 NotifyPropertyChanged();
266 /// The mute status, true or false.
268 /// <since_tizen> 3 </since_tizen>
273 return (bool)GetValue(MutedProperty);
277 SetValue(MutedProperty, value);
278 NotifyPropertyChanged();
283 /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
285 /// <since_tizen> 3 </since_tizen>
286 public PropertyMap Volume
290 return (PropertyMap)GetValue(VolumeProperty);
294 SetValue(VolumeProperty, value);
295 NotifyPropertyChanged();
300 /// Video rendering by underlay, true or false.<br />
301 /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
303 /// <since_tizen> 4 </since_tizen>
308 return (bool)GetValue(UnderlayProperty);
312 SetValue(UnderlayProperty, value);
313 NotifyPropertyChanged();
318 /// Video file URL as string type.
320 /// <since_tizen> 4 </since_tizen>
321 public string ResourceUrl
325 return (string)GetValue(ResourceUrlProperty);
329 SetValue(ResourceUrlProperty, value);
330 NotifyPropertyChanged();
335 /// Starts the video playback.
337 /// <since_tizen> 3 </since_tizen>
340 Interop.VideoView.Play(SwigCPtr);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 /// Pauses the video playback.
347 /// <since_tizen> 3 </since_tizen>
350 Interop.VideoView.Pause(SwigCPtr);
351 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 /// Stops the video playback.
357 /// <since_tizen> 3 </since_tizen>
360 Interop.VideoView.Stop(SwigCPtr);
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// Seeks forward by the specified number of milliseconds.
367 /// <param name="millisecond">The position for forward playback.</param>
368 /// <since_tizen> 3 </since_tizen>
369 public void Forward(int millisecond)
371 Interop.VideoView.Forward(SwigCPtr, millisecond);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 /// Seeks backward by the specified number of milliseconds.
378 /// <param name="millisecond">The position for backward playback.</param>
379 /// <since_tizen> 3 </since_tizen>
380 public void Backward(int millisecond)
382 Interop.VideoView.Backward(SwigCPtr, millisecond);
383 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 internal VideoViewSignal FinishedSignal()
388 VideoViewSignal ret = new VideoViewSignal(Interop.VideoView.FinishedSignal(SwigCPtr), false);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(VideoView obj)
395 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
401 /// <param name="type">DisposeTypes</param>
402 /// <since_tizen> 3 </since_tizen>
403 protected override void Dispose(DisposeTypes type)
410 //Release your own unmanaged resources here.
411 //You should not access any managed member here except static instance.
412 //because the execution order of Finalizes is non-deterministic.
414 if (this != null && videoViewFinishedCallbackDelegate != null)
416 FinishedSignal().Disconnect(videoViewFinishedCallbackDelegate);
422 /// This will not be public opened.
423 [EditorBrowsable(EditorBrowsableState.Never)]
424 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
426 Interop.VideoView.DeleteVideoView(swigCPtr);
429 // Callback for VideoView Finished signal
430 private void OnFinished(IntPtr data)
432 if (videoViewFinishedEventHandler != null)
434 FinishedEventArgs e = new FinishedEventArgs();
436 // Populate all members of "e" (FinishedEventArgs) with real data
437 e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
438 //here we send all data to user event handlers
439 videoViewFinishedEventHandler(this, e);
444 /// Event arguments that passed via the finished signal.
446 /// <since_tizen> 3 </since_tizen>
447 public class FinishedEventArgs : EventArgs
449 private VideoView videoView;
452 /// The view for video playback and display.
454 /// <since_tizen> 3 </since_tizen>
455 public VideoView VideoView
468 internal new class Property
470 internal static readonly int VIDEO = Interop.VideoView.VideoGet();
471 internal static readonly int LOOPING = Interop.VideoView.LoopingGet();
472 internal static readonly int MUTED = Interop.VideoView.MutedGet();
473 internal static readonly int VOLUME = Interop.VideoView.VolumeGet();
474 internal static readonly int UNDERLAY = Interop.VideoView.UnderlayGet();
477 internal System.IntPtr GetNativePlayerHandle()
479 var ret = Interop.VideoView.GetNativePlayerHandle(SwigCPtr);
480 NUILog.Debug($"NativePlayerHandle=0x{ret:X}");
486 /// Contains and encapsulates Native Player handle.
488 [EditorBrowsable(EditorBrowsableState.Never)]
489 public class SafeNativePlayerHandle : SafeHandle
492 /// Constructor, null handle is set.
494 [EditorBrowsable(EditorBrowsableState.Never)]
495 public SafeNativePlayerHandle() : base(global::System.IntPtr.Zero, false)
500 /// Constructor, Native player handle is set to handle.
502 [EditorBrowsable(EditorBrowsableState.Never)]
503 public SafeNativePlayerHandle(VideoView videoView) : base(global::System.IntPtr.Zero, false)
505 if (videoView != null)
507 SetHandle(videoView.GetNativePlayerHandle());
512 /// Null check if the handle is valid or not.
514 [EditorBrowsable(EditorBrowsableState.Never)]
515 public override bool IsInvalid
519 return handle == global::System.IntPtr.Zero;
523 /// Release handle itself.
525 /// <returns>true when released successfully.</returns>
526 [EditorBrowsable(EditorBrowsableState.Never)]
527 protected override bool ReleaseHandle()
529 SetHandle(global::System.IntPtr.Zero);