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 BindableProperty VideoProperty = null;
33 internal static void SetInternalVideoProperty(BindableObject bindable, object oldValue, object newValue)
35 var videoView = (VideoView)bindable;
38 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
41 internal static object GetInternalVideoProperty(BindableObject bindable)
43 var videoView = (VideoView)bindable;
44 PropertyMap temp = new PropertyMap();
45 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO).Get(temp);
49 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
50 [EditorBrowsable(EditorBrowsableState.Never)]
51 public static BindableProperty LoopingProperty = null;
52 internal static void SetInternalLoopingProperty(BindableObject bindable, object oldValue, object newValue)
54 var videoView = (VideoView)bindable;
57 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.LOOPING, new Tizen.NUI.PropertyValue((bool)newValue));
60 internal static object GetInternalLoopingProperty(BindableObject bindable)
62 var videoView = (VideoView)bindable;
64 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.LOOPING).Get(out temp);
68 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 public static BindableProperty MutedProperty = null;
71 internal static void SetInternalMutedProperty(BindableObject bindable, object oldValue, object newValue)
73 var videoView = (VideoView)bindable;
76 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.MUTED, new Tizen.NUI.PropertyValue((bool)newValue));
79 internal static object GetInternalMutedProperty(BindableObject bindable)
81 var videoView = (VideoView)bindable;
83 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.MUTED).Get(out temp);
87 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public static BindableProperty VolumeProperty = null;
90 internal static void SetInternalVolumeProperty(BindableObject bindable, object oldValue, object newValue)
92 var videoView = (VideoView)bindable;
95 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VOLUME, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
98 internal static object GetInternalVolumeProperty(BindableObject bindable)
100 var videoView = (VideoView)bindable;
101 PropertyMap temp = new PropertyMap();
102 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VOLUME).Get(temp);
106 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
107 [EditorBrowsable(EditorBrowsableState.Never)]
108 public static BindableProperty UnderlayProperty = null;
109 internal static void SetInternalUnderlayProperty(BindableObject bindable, object oldValue, object newValue)
111 var videoView = (VideoView)bindable;
112 if (newValue != null)
114 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.UNDERLAY, new Tizen.NUI.PropertyValue((bool)newValue));
117 internal static object GetInternalUnderlayProperty(BindableObject bindable)
119 var videoView = (VideoView)bindable;
121 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.UNDERLAY).Get(out temp);
125 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public static BindableProperty ResourceUrlProperty = null;
128 internal static void SetInternalResourceUrlProperty(BindableObject bindable, object oldValue, object newValue)
130 var videoView = (VideoView)bindable;
131 if (newValue != null)
133 Tizen.NUI.Object.SetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO, new Tizen.NUI.PropertyValue((string)newValue));
136 internal static object GetInternalResourceUrlProperty(BindableObject bindable)
138 var videoView = (VideoView)bindable;
140 Tizen.NUI.Object.GetProperty((HandleRef)videoView.SwigCPtr, VideoView.Property.VIDEO).Get(out temp);
144 private FinishedCallbackDelegate videoViewFinishedCallbackDelegate;
145 private EventHandler<FinishedEventArgs> videoViewFinishedEventHandler;
150 if (NUIApplication.IsUsingXaml)
152 VideoProperty = BindableProperty.Create(nameof(Video), typeof(PropertyMap), typeof(VideoView), null,
153 propertyChanged: SetInternalVideoProperty, defaultValueCreator: GetInternalVideoProperty);
155 LoopingProperty = BindableProperty.Create(nameof(Looping), typeof(bool), typeof(VideoView), false,
156 propertyChanged: SetInternalLoopingProperty, defaultValueCreator: GetInternalLoopingProperty);
158 MutedProperty = BindableProperty.Create(nameof(Muted), typeof(bool), typeof(VideoView), false,
159 propertyChanged: SetInternalMutedProperty, defaultValueCreator: GetInternalMutedProperty);
161 VolumeProperty = BindableProperty.Create(nameof(Volume), typeof(PropertyMap), typeof(VideoView), null,
162 propertyChanged: SetInternalVolumeProperty, defaultValueCreator: GetInternalVolumeProperty);
164 UnderlayProperty = BindableProperty.Create(nameof(Underlay), typeof(bool), typeof(VideoView), false,
165 propertyChanged: SetInternalUnderlayProperty, defaultValueCreator: GetInternalUnderlayProperty);
167 ResourceUrlProperty = BindableProperty.Create(nameof(ResourceUrl), typeof(string), typeof(VideoView), string.Empty,
168 propertyChanged: SetInternalResourceUrlProperty, defaultValueCreator: GetInternalResourceUrlProperty);
173 /// Creates an initialized VideoView.
175 /// <since_tizen> 3 </since_tizen>
176 public VideoView() : this(Interop.VideoView.New(), true)
178 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182 /// Creates an initialized VideoView.<br />
183 /// If the string is empty, VideoView will not display anything.<br />
185 /// <param name="url">The URL of the video resource to display.</param>
186 /// <since_tizen> 3 </since_tizen>
187 public VideoView(string url) : this(Interop.VideoView.New(url), true)
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193 /// Creates an initialized VideoView.<br />
194 /// If the string is empty, VideoView will not display anything.<br />
196 /// <param name="swCodec">Video rendering by H/W codec if false.</param>
197 [EditorBrowsable(EditorBrowsableState.Never)]
198 public VideoView(bool swCodec) : this(Interop.VideoView.New(swCodec), true)
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
204 /// Creates an initialized VideoView.<br />
205 /// If the string is empty, VideoView will not display anything.<br />
207 /// <param name="url">The URL of the video resource to display.</param>
208 /// <param name="swCodec">Video rendering by H/W codec if false.</param>
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public VideoView(string url, bool swCodec) : this(Interop.VideoView.New(url, swCodec), true)
212 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 /// Hidden API (Inhouse API).
217 /// Using Uri class to provide safe service and secure API.
218 /// Creates an initialized VideoView.
219 /// If the string is empty, VideoView will not display anything.
221 /// <param name="uri">The URI of the video resource to display.</param>
222 /// <param name="swCodec">Video rendering by H/W codec if false.</param>
223 [EditorBrowsable(EditorBrowsableState.Never)]
224 public VideoView(Uri uri, bool swCodec) : this(Interop.VideoView.New((uri == null) ? String.Empty : uri.AbsoluteUri, swCodec), true)
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 internal VideoView(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
233 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
234 private delegate void FinishedCallbackDelegate(IntPtr data);
237 /// Event for the finished signal which can be used to subscribe or unsubscribe the event handler
238 /// The finished signal is emitted when a video playback has finished.<br />
240 /// <since_tizen> 3 </since_tizen>
241 public event EventHandler<FinishedEventArgs> Finished
245 if (videoViewFinishedEventHandler == null)
247 videoViewFinishedCallbackDelegate = (OnFinished);
248 FinishedSignal().Connect(videoViewFinishedCallbackDelegate);
250 videoViewFinishedEventHandler += value;
254 videoViewFinishedEventHandler -= value;
255 if (videoViewFinishedEventHandler == null && FinishedSignal().Empty() == false)
257 FinishedSignal().Disconnect(videoViewFinishedCallbackDelegate);
263 /// Video file setting type of PropertyMap.
265 /// <since_tizen> 3 </since_tizen>
266 public PropertyMap Video
270 if (NUIApplication.IsUsingXaml)
272 return (PropertyMap)GetValue(VideoProperty);
276 return (PropertyMap)GetInternalVideoProperty(this);
281 if (NUIApplication.IsUsingXaml)
283 SetValue(VideoProperty, value);
287 SetInternalVideoProperty(this, null, value);
289 NotifyPropertyChanged();
294 /// The looping status, true or false.
296 /// <since_tizen> 3 </since_tizen>
301 if (NUIApplication.IsUsingXaml)
303 return (bool)GetValue(LoopingProperty);
307 return (bool)GetInternalLoopingProperty(this);
312 if (NUIApplication.IsUsingXaml)
314 SetValue(LoopingProperty, value);
318 SetInternalLoopingProperty(this, null, value);
320 NotifyPropertyChanged();
325 /// The mute status, true or false.
327 /// <since_tizen> 3 </since_tizen>
332 if (NUIApplication.IsUsingXaml)
334 return (bool)GetValue(MutedProperty);
338 return (bool)GetInternalMutedProperty(this);
343 if (NUIApplication.IsUsingXaml)
345 SetValue(MutedProperty, value);
349 SetInternalMutedProperty(this, null, value);
351 NotifyPropertyChanged();
356 /// The left and the right volume scalar as float type, PropertyMap with two values ( "left" and "right" ).
358 /// <since_tizen> 3 </since_tizen>
359 public PropertyMap Volume
363 if (NUIApplication.IsUsingXaml)
365 return (PropertyMap)GetValue(VolumeProperty);
369 return (PropertyMap)GetInternalVolumeProperty(this);
374 if (NUIApplication.IsUsingXaml)
376 SetValue(VolumeProperty, value);
380 SetInternalVolumeProperty(this, null, value);
382 NotifyPropertyChanged();
387 /// Video rendering by underlay, true or false.<br />
388 /// This shows video composited underneath the window by the system. This means it may ignore rotation of the video-view.
390 /// <since_tizen> 4 </since_tizen>
396 if (NUIApplication.IsUsingXaml)
398 return (bool)GetValue(UnderlayProperty);
402 return (bool)GetInternalUnderlayProperty(this);
407 if (NUIApplication.IsUsingXaml)
409 SetValue(UnderlayProperty, value);
413 SetInternalUnderlayProperty(this, null, value);
415 NotifyPropertyChanged();
420 /// Video file URL as string type.
422 /// <since_tizen> 4 </since_tizen>
423 public string ResourceUrl
427 if (NUIApplication.IsUsingXaml)
429 return (string)GetValue(ResourceUrlProperty);
433 return (string)GetInternalResourceUrlProperty(this);
438 if (NUIApplication.IsUsingXaml)
440 SetValue(ResourceUrlProperty, value);
444 SetInternalResourceUrlProperty(this, null, value);
446 NotifyPropertyChanged();
451 /// Starts the video playback.
453 /// <since_tizen> 3 </since_tizen>
456 Interop.VideoView.Play(SwigCPtr);
457 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461 /// Pauses the video playback.
463 /// <since_tizen> 3 </since_tizen>
466 Interop.VideoView.Pause(SwigCPtr);
467 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
471 /// Stops the video playback.
473 /// <since_tizen> 3 </since_tizen>
476 Interop.VideoView.Stop(SwigCPtr);
477 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
481 /// Seeks forward by the specified number of milliseconds.
483 /// <param name="millisecond">The position for forward playback.</param>
484 /// <since_tizen> 3 </since_tizen>
485 public void Forward(int millisecond)
487 Interop.VideoView.Forward(SwigCPtr, millisecond);
488 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
492 /// Seeks backward by the specified number of milliseconds.
494 /// <param name="millisecond">The position for backward playback.</param>
495 /// <since_tizen> 3 </since_tizen>
496 public void Backward(int millisecond)
498 Interop.VideoView.Backward(SwigCPtr, millisecond);
499 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503 /// Get native player handle.
505 /// How to get native player handle
507 /// VideoView videoView = new VideoView();
508 /// videoView.ResourceUrl = "some video path";
509 /// var handle = videoView.NativeHandle;
510 /// if(handle.IsInvalid == false)
512 /// IntPtr nativeHandle = handle.DangerousGetHandle();
513 /// // do something with nativeHandle
518 /// <since_tizen> 9 </since_tizen>
519 public SafeHandle NativeHandle
523 return new NUI.SafeNativePlayerHandle(this);
527 internal VideoViewSignal FinishedSignal()
529 VideoViewSignal ret = new VideoViewSignal(Interop.VideoView.FinishedSignal(SwigCPtr), false);
530 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
537 /// <param name="type">DisposeTypes</param>
538 /// <since_tizen> 3 </since_tizen>
539 protected override void Dispose(DisposeTypes type)
546 //Release your own unmanaged resources here.
547 //You should not access any managed member here except static instance.
548 //because the execution order of Finalizes is non-deterministic.
550 if (this != null && videoViewFinishedCallbackDelegate != null)
552 FinishedSignal().Disconnect(videoViewFinishedCallbackDelegate);
558 /// This will not be public opened.
559 [EditorBrowsable(EditorBrowsableState.Never)]
560 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
562 Interop.VideoView.DeleteVideoView(swigCPtr);
565 // Callback for VideoView Finished signal
566 private void OnFinished(IntPtr data)
568 if (videoViewFinishedEventHandler != null)
570 FinishedEventArgs e = new FinishedEventArgs();
572 // Populate all members of "e" (FinishedEventArgs) with real data
573 e.VideoView = Registry.GetManagedBaseHandleFromNativePtr(data) as VideoView;
574 //here we send all data to user event handlers
575 videoViewFinishedEventHandler(this, e);
580 /// Event arguments that passed via the finished signal.
582 /// <since_tizen> 3 </since_tizen>
583 public class FinishedEventArgs : EventArgs
585 private VideoView videoView;
588 /// The view for video playback and display.
590 /// <since_tizen> 3 </since_tizen>
591 public VideoView VideoView
604 internal new class Property
606 internal static readonly int VIDEO = Interop.VideoView.VideoGet();
607 internal static readonly int LOOPING = Interop.VideoView.LoopingGet();
608 internal static readonly int MUTED = Interop.VideoView.MutedGet();
609 internal static readonly int VOLUME = Interop.VideoView.VolumeGet();
610 internal static readonly int UNDERLAY = Interop.VideoView.UnderlayGet();
613 internal System.IntPtr GetNativePlayerHandle()
615 var ret = Interop.VideoView.GetNativePlayerHandle(SwigCPtr);
616 NUILog.Debug($"NativePlayerHandle=0x{ret:X}");
622 /// Contains and encapsulates Native Player handle.
624 [EditorBrowsable(EditorBrowsableState.Never)]
625 [Obsolete("This has been deprecated in API9 and will be removed in API11. Use VideoView.NativeHandle instead.")]
626 public class SafeNativePlayerHandle : SafeHandle
629 /// Constructor, null handle is set.
631 [EditorBrowsable(EditorBrowsableState.Never)]
632 public SafeNativePlayerHandle() : base(global::System.IntPtr.Zero, false)
637 /// Constructor, Native player handle is set to handle.
639 [EditorBrowsable(EditorBrowsableState.Never)]
640 public SafeNativePlayerHandle(VideoView videoView) : base(global::System.IntPtr.Zero, false)
642 if (videoView != null)
644 SetHandle(videoView.GetNativePlayerHandle());
649 /// Null check if the handle is valid or not.
651 [EditorBrowsable(EditorBrowsableState.Never)]
652 public override bool IsInvalid
656 return handle == global::System.IntPtr.Zero;
660 /// Release handle itself.
662 /// <returns>true when released successfully.</returns>
663 [EditorBrowsable(EditorBrowsableState.Never)]
664 protected override bool ReleaseHandle()
666 SetHandle(global::System.IntPtr.Zero);