[NUI] Add SafeNativePlayerHandler to pass native player handle (#1398)
authordongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 12 Feb 2020 02:54:54 +0000 (11:54 +0900)
committerGitHub <noreply@github.com>
Wed, 12 Feb 2020 02:54:54 +0000 (11:54 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.VideoView.cs
src/Tizen.NUI/src/public/BaseComponents/VideoView.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VideoViewTest.cs [new file with mode: 0755]
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Tizen.NUI.Samples.csproj
test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/v.mp4 [new file with mode: 0755]

index ff017e2..0dec657 100755 (executable)
@@ -97,6 +97,10 @@ namespace Tizen.NUI
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_delete_VideoViewSignal")]
             public static extern void delete_VideoViewSignal(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+            [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_VideoView_GetNativePlayerHandle")]
+            public static extern global::System.IntPtr GetNativePlayerHandle(global::System.Runtime.InteropServices.HandleRef jarg1);
+
         }
     }
 }
\ No newline at end of file
index e7c415d..e2e3000 100755 (executable)
@@ -460,5 +460,61 @@ namespace Tizen.NUI.BaseComponents
             internal static readonly int VOLUME = Interop.VideoView.VideoView_Property_VOLUME_get();
             internal static readonly int UNDERLAY = Interop.VideoView.VideoView_Property_UNDERLAY_get();
         }
+
+        internal System.IntPtr GetNativePlayerHandle()
+        {
+            var ret = Interop.VideoView.GetNativePlayerHandle(swigCPtr);
+            NUILog.Debug($"NativePlayerHandle=0x{ret:X}");
+            return ret;
+        }
+    }
+
+    /// <summary>
+    /// Contains and encapsulates Native Player handle.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public class SafeNativePlayerHandle : SafeHandle
+    {
+        /// <summary>
+        /// Contructor, null handle is set.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public SafeNativePlayerHandle() : base(global::System.IntPtr.Zero, false)
+        {
+        }
+
+        /// <summary>
+        /// Contructor, Native player handle is set to handle.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public SafeNativePlayerHandle(VideoView videoView) : base(global::System.IntPtr.Zero, false)
+        {
+            if(videoView != null)
+            {
+                SetHandle(videoView.GetNativePlayerHandle());
+            }
+        }
+
+        /// <summary>
+        /// Null check if the handle is valid or not.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public override bool IsInvalid
+        {
+            get
+            {
+                return handle == global::System.IntPtr.Zero;
+            }
+        }
+        /// <summary>
+        /// Release handle itself.
+        /// </summary>
+        /// <returns>true when released successfully.</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        protected override bool ReleaseHandle()
+        {
+            SetHandle(global::System.IntPtr.Zero);
+            return true;
+        }
     }
 }
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VideoViewTest.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/VideoViewTest.cs
new file mode 100755 (executable)
index 0000000..bdbe973
--- /dev/null
@@ -0,0 +1,137 @@
+
+using global::System;
+using Tizen.NUI.BaseComponents;
+
+namespace Tizen.NUI.Samples
+{
+    using tlog = Tizen.Log;
+
+    public class VideoViewTest : IExample
+    {
+        // Make derieved class from Tizen.Multimedia.Player because protected Player(IntPtr handle, Action<int, string> errorHandler)
+        // this constructor's access modifyer is protected, so there is no other way.
+        public class myPlayer : Tizen.Multimedia.Player
+        {
+            public myPlayer() : base()
+            {
+                //Initialize();
+            }
+
+            public myPlayer(IntPtr p) : base(p, null)
+            {
+                //Initialize();
+            }
+        }
+
+        Window win;
+        myPlayer player;
+        string resourcePath;
+        const string tag = "NUITEST";
+        public void Activate()
+        {
+            win = NUIApplication.GetDefaultWindow();
+            win.BackgroundColor = Color.Green;
+            win.KeyEvent += Win_KeyEvent;
+            win.TouchEvent += Win_TouchEvent;
+
+            var dummy = new View();
+            dummy.Size = new Size(200, 200);
+            dummy.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.2f);
+            win.Add(dummy);
+
+            resourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "v.mp4";
+            tlog.Fatal(tag, $"resourcePath: {resourcePath}");
+
+            NUIVideoViewTest();
+            //PlayerTest();
+        }
+        public void Deactivate()
+        {
+            win.KeyEvent -= Win_KeyEvent;
+            win.TouchEvent -= Win_TouchEvent;
+            videoView?.Unparent();
+            player?.Dispose();
+            player = null;
+        }
+
+        int cnt;
+        private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
+        {
+            if (e.Touch.GetState(0) == PointStateType.Down)
+            {
+                if (++cnt % 2 == 1)
+                {
+                    if (player != null)
+                    {
+                        player.Pause();
+                        tlog.Fatal(tag, $"player pause!");
+                    }
+                }
+                else
+                {
+                    if (player != null)
+                    {
+                        player.Start();
+                        tlog.Fatal(tag, $"player start!");
+                    }
+                }
+            }
+        }
+
+        public async void PlayerTest()
+        {
+            player = new myPlayer();
+
+            player.SetSource(new Tizen.Multimedia.MediaUriSource(resourcePath));
+
+            player.Display = new Tizen.Multimedia.Display(win);
+
+            await player.PrepareAsync();
+            tlog.Fatal(tag, $"await player.PrepareAsync();");
+
+            player.Start();
+            tlog.Fatal(tag, $"player.Start();");
+
+            if (player.DisplaySettings.IsVisible == false)
+            {
+                player.DisplaySettings.IsVisible = true;
+            }
+            tlog.Fatal(tag, $"Display visible = {player.DisplaySettings.IsVisible}");
+
+            player.DisplaySettings.Mode = Tizen.Multimedia.PlayerDisplayMode.FullScreen;
+        }
+
+        VideoView videoView;
+        public void NUIVideoViewTest()
+        {
+            videoView = new VideoView();
+            videoView.ResourceUrl = resourcePath;
+            videoView.Looping = true;
+            videoView.Size = new Size(300, 300);
+            videoView.PositionUsesPivotPoint = true;
+            videoView.ParentOrigin = ParentOrigin.Center;
+            videoView.PivotPoint = PivotPoint.Center;
+            win.Add(videoView);
+
+            var playerHandle = new SafeNativePlayerHandler(videoView);
+            player = new myPlayer(playerHandle.DangerousGetHandle());
+            if (player != null)
+            {
+                player.Start();
+            }
+        }
+
+        private void Win_KeyEvent(object sender, Window.KeyEventArgs e)
+        {
+            if (e.Key.State == Key.StateType.Down)
+            {
+                tlog.Fatal(tag, $"key pressed name={e.Key.KeyPressedName}");
+                if (e.Key.KeyPressedName == "XF86Back")
+                {
+                    Deactivate();
+                }
+            }
+        }
+
+    }
+}
index 1495687..55110f7 100755 (executable)
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>None</DebugType>
   </PropertyGroup>
+  <ItemGroup>
+    <Compile Remove="Samples\AnimatedImageViewTest.cs" />
+    <Compile Remove="Samples\AnimatedVectorImageViewTest.cs" />
+    <Compile Remove="Samples\ButtonSample.cs" />
+    <Compile Remove="Samples\CheckBoxSample.cs" />
+    <Compile Remove="Samples\DropDownSample.cs" />
+    <Compile Remove="Samples\PopupSample.cs" />
+    <Compile Remove="Samples\RadioButtonSample.cs" />
+  </ItemGroup>
 
   <ItemGroup>
     <PackageReference Include="Tizen.NET" Version="8.0.0.15045" />
diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/v.mp4 b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/v.mp4
new file mode 100755 (executable)
index 0000000..cd7dcd0
Binary files /dev/null and b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/res/v.mp4 differ