Revert "[NUI] Dialog and AlertDialog code refactoring with adding DialogPage"
[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         View dummy;
31         public void Activate()
32         {
33             win = NUIApplication.GetDefaultWindow();
34             win.BackgroundColor = new Color(1, 1, 1, 0);
35             win.KeyEvent += Win_KeyEvent;
36             win.TouchEvent += Win_TouchEvent;
37
38             dummy = new View();
39             dummy.Size = new Size(200, 200);
40             dummy.BackgroundColor = new Color(1, 1, 1, 0.5f);
41             win.Add(dummy);
42
43             resourcePath = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "v.mp4";
44             tlog.Fatal(tag, $"resourcePath: {resourcePath}");
45
46             NUIVideoViewTest();
47             //PlayerTest();
48         }
49         public void Deactivate()
50         {
51             win.KeyEvent -= Win_KeyEvent;
52             win.TouchEvent -= Win_TouchEvent;
53
54             tlog.Fatal(tag, $"Deactivate()!");
55
56             dummy.Unparent();
57
58             videoView.Unparent();
59
60             // currently it is crashed when Dispose() is called. need to check.
61             //videoView.Dispose();
62             //videoView = null;
63             //player.Unprepare();
64             //player.Dispose();
65             //player = null;
66             tlog.Fatal(tag, $"Deactivate()! videoView dispsed");
67         }
68
69         int cnt;
70         private void Win_TouchEvent(object sender, Window.TouchEventArgs e)
71         {
72             if (e.Touch.GetState(0) == PointStateType.Down)
73             {
74                 if (++cnt % 2 == 1)
75                 {
76                     if (player != null)
77                     {
78                         player.Pause();
79                         tlog.Fatal(tag, $"player pause!");
80                     }
81                 }
82                 else
83                 {
84                     if (player != null)
85                     {
86                         player.Start();
87                         tlog.Fatal(tag, $"player start!");
88                     }
89                 }
90             }
91         }
92
93         public async void PlayerTest()
94         {
95             player = new myPlayer();
96
97             player.SetSource(new Tizen.Multimedia.MediaUriSource(resourcePath));
98
99             player.Display = new Tizen.Multimedia.Display(win);
100
101             await player.PrepareAsync().ConfigureAwait(false);
102             tlog.Fatal(tag, $"await player.PrepareAsync();");
103
104             player.Start();
105             tlog.Fatal(tag, $"player.Start();");
106
107             if (player.DisplaySettings.IsVisible == false)
108             {
109                 player.DisplaySettings.IsVisible = true;
110             }
111             tlog.Fatal(tag, $"Display visible = {player.DisplaySettings.IsVisible}");
112
113             player.DisplaySettings.Mode = Tizen.Multimedia.PlayerDisplayMode.FullScreen;
114         }
115
116         VideoView videoView;
117         public void NUIVideoViewTest()
118         {
119             videoView = new VideoView();
120             videoView.ResourceUrl = resourcePath;
121             videoView.Looping = true;
122             videoView.Size = new Size(300, 300);
123             videoView.PositionUsesPivotPoint = true;
124             videoView.ParentOrigin = ParentOrigin.Center;
125             videoView.PivotPoint = PivotPoint.Center;
126             win.Add(videoView);
127
128             var playerHandle = new SafeNativePlayerHandle(videoView);
129             player = new myPlayer(playerHandle.DangerousGetHandle());
130             if (player != null)
131             {
132                 player.Start();
133             }
134         }
135
136         private void Win_KeyEvent(object sender, Window.KeyEventArgs e)
137         {
138             if (e.Key.State == Key.StateType.Down)
139             {
140                 tlog.Fatal(tag, $"key pressed name={e.Key.KeyPressedName}");
141                 if (e.Key.KeyPressedName == "XF86Back")
142                 {
143                     Deactivate();
144                 }
145             }
146         }
147
148     }
149 }