a42d5ffb96500084f1a79ec6d0d0320a333f0c1d
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / VideoViewTest.cs
1 
2 using global::System;
3 using Tizen.NUI.BaseComponents;
4
5 namespace Tizen.NUI.Samples
6 {
7     using tlog = Tizen.Log;
8
9     public class VideoViewTest : IExample
10     {
11         // Make derieved class from Tizen.Multimedia.Player because protected Player(IntPtr handle, Action<int, string> errorHandler)
12         // this constructor's access modifyer is protected, so there is no other way.
13         public class myPlayer : Tizen.Multimedia.Player
14         {
15             public myPlayer() : base()
16             {
17                 //Initialize();
18             }
19
20             public myPlayer(IntPtr p) : base(p, null)
21             {
22                 //Initialize();
23             }
24         }
25
26         Window win;
27         myPlayer player;
28         string resourcePath;
29         const string tag = "NUITEST";
30         public void Activate()
31         {
32             win = NUIApplication.GetDefaultWindow();
33             win.BackgroundColor = Color.Green;
34             win.KeyEvent += Win_KeyEvent;
35             win.TouchEvent += Win_TouchEvent;
36
37             var dummy = new View();
38             dummy.Size = new Size(200, 200);
39             dummy.BackgroundColor = new Color(0.0f, 0.0f, 0.0f, 0.2f);
40             win.Add(dummy);
41
42             resourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "v.mp4";
43             tlog.Fatal(tag, $"resourcePath: {resourcePath}");
44
45             NUIVideoViewTest();
46             //PlayerTest();
47         }
48         public void Deactivate()
49         {
50             win.KeyEvent -= Win_KeyEvent;
51             win.TouchEvent -= Win_TouchEvent;
52             videoView?.Unparent();
53             player?.Dispose();
54             player = null;
55         }
56
57         int cnt;
58         private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
59         {
60             if (e.Touch.GetState(0) == PointStateType.Down)
61             {
62                 if (++cnt % 2 == 1)
63                 {
64                     if (player != null)
65                     {
66                         player.Pause();
67                         tlog.Fatal(tag, $"player pause!");
68                     }
69                 }
70                 else
71                 {
72                     if (player != null)
73                     {
74                         player.Start();
75                         tlog.Fatal(tag, $"player start!");
76                     }
77                 }
78             }
79         }
80
81         public async void PlayerTest()
82         {
83             player = new myPlayer();
84
85             player.SetSource(new Tizen.Multimedia.MediaUriSource(resourcePath));
86
87             player.Display = new Tizen.Multimedia.Display(win);
88
89             await player.PrepareAsync();
90             tlog.Fatal(tag, $"await player.PrepareAsync();");
91
92             player.Start();
93             tlog.Fatal(tag, $"player.Start();");
94
95             if (player.DisplaySettings.IsVisible == false)
96             {
97                 player.DisplaySettings.IsVisible = true;
98             }
99             tlog.Fatal(tag, $"Display visible = {player.DisplaySettings.IsVisible}");
100
101             player.DisplaySettings.Mode = Tizen.Multimedia.PlayerDisplayMode.FullScreen;
102         }
103
104         VideoView videoView;
105         public void NUIVideoViewTest()
106         {
107             videoView = new VideoView();
108             videoView.ResourceUrl = resourcePath;
109             videoView.Looping = true;
110             videoView.Size = new Size(300, 300);
111             videoView.PositionUsesPivotPoint = true;
112             videoView.ParentOrigin = ParentOrigin.Center;
113             videoView.PivotPoint = PivotPoint.Center;
114             win.Add(videoView);
115
116             var playerHandle = new SafeNativePlayerHandle(videoView);
117             player = new myPlayer(playerHandle.DangerousGetHandle());
118             if (player != null)
119             {
120                 player.Start();
121             }
122         }
123
124         private void Win_KeyEvent(object sender, Window.KeyEventArgs e)
125         {
126             if (e.Key.State == Key.StateType.Down)
127             {
128                 tlog.Fatal(tag, $"key pressed name={e.Key.KeyPressedName}");
129                 if (e.Key.KeyPressedName == "XF86Back")
130                 {
131                     Deactivate();
132                 }
133             }
134         }
135
136     }
137 }