DayZ 1.24
Loading...
Searching...
No Matches
VideoPlayer.c
Go to the documentation of this file.
1class VideoPlayer extends ScriptedWidgetEventHandler
2{
3 protected Widget m_Root;
4
7
9
12
15
17
20
22 /*protected*/ VideoWidget m_VideoWidget;
23
24 void VideoPlayer(Widget parent)
25 {
26 m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/video_player.layout", parent);
27 m_Root.SetHandler(this);
28 m_Root.SetSort(333);
29 Init();
30 }
31
33 {
34 }
35
36 void Show(bool show)
37 {
38 m_Root.Show(show);
39 }
40
41 private void Init()
42 {
43 m_PlayButton = ButtonWidget.Cast(m_Root.FindAnyWidget("vp_PlayButton"));
44 m_PauseButton = ButtonWidget.Cast(m_Root.FindAnyWidget("vp_PauseButton"));
45 m_StopButton = ButtonWidget.Cast(m_Root.FindAnyWidget("vp_StopButton"));
46
47 m_OnceButton = ButtonWidget.Cast(m_Root.FindAnyWidget("vp_OnceButton"));
48 m_RepeatButton = ButtonWidget.Cast(m_Root.FindAnyWidget("vp_RepeatButton"));
49
50 m_LoadButton = ButtonWidget.Cast(m_Root.FindAnyWidget("vp_LoadButton"));
51 m_LoadVideo = GridSpacerWidget.Cast(m_Root.FindAnyWidget("vp_LoadVideo"));
52 m_LoadVideo.Show(false);
53
54 m_Progress = SliderWidget.Cast(m_Root.FindAnyWidget("vp_Progress"));
55 m_Progress.SetCurrent(0);
56
57 m_CurrentTime = TextWidget.Cast(m_Root.FindAnyWidget("vp_CurrentTime"));
58 m_TotalTime = TextWidget.Cast(m_Root.FindAnyWidget("vp_TotalTime"));
59
60 m_Buffering = ImageWidget.Cast(m_Root.FindAnyWidget("vp_Buffering"));
61 m_Buffering.Show(false);
62 m_VideoWidget = VideoWidget.Cast(m_Root.FindAnyWidget("vp_Video"));
63
64 m_VideoWidget.SetCallback(VideoCallback.ON_PLAY, OnPlaybackStart);
65 m_VideoWidget.SetCallback(VideoCallback.ON_PAUSE, OnPlaybackStop);
66 m_VideoWidget.SetCallback(VideoCallback.ON_STOP, OnPlaybackStop);
67 m_VideoWidget.SetCallback(VideoCallback.ON_END, OnPlaybackStop);
68 m_VideoWidget.SetCallback(VideoCallback.ON_LOAD, OnPlaybackStop);
69 m_VideoWidget.SetCallback(VideoCallback.ON_SEEK, UpdateCurrentTime);
70 m_VideoWidget.SetCallback(VideoCallback.ON_BUFFERING_START, OnBufferingStart);
71 m_VideoWidget.SetCallback(VideoCallback.ON_BUFFERING_END, OnBufferingEnd);
72 }
73
74 private void InitVideoLoading()
75 {
76 string path = "video\\*";
77
78 string fileName;
80
82
83 if (fileName != "")
85
86 while (FindNextFile(handle, fileName, fileAttr))
88
89 CloseFindFile(handle);
90 }
91
93 {
94 Widget entry = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/video_player_entry.layout", m_LoadVideo);
95 ButtonWidget entryButton = ButtonWidget.Cast(entry.GetChildren());
96 entryButton.SetText(entryName);
97 entryButton.SetUserID(333);
98 }
99
100 private void UpdateCurrentTime()
101 {
102 int time = m_VideoWidget.GetTime();
103 UpdateTime(m_CurrentTime, time);
104
105 m_Progress.SetCurrent(time);
106 }
107
108 // This can be an async op
109 private void UpdateTotalTime()
110 {
111 int time = m_VideoWidget.GetTotalTime();
112
113 if (time != 0)
114 {
115 UpdateTime(m_TotalTime, time);
116 m_Progress.SetMinMax(0, time);
117 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(UpdateTotalTime);
118 }
119 }
120
121 private void UpdateTime(TextWidget widget, int time)
122 {
124 TimeConversions.ConvertSecondsToFullTime(time / 1000, timeData);
125 widget.SetText(timeData.FormatedAsTimestamp());
126 }
127
128 override bool OnChange(Widget w, int x, int y, bool finished)
129 {
130 if (w == m_Progress)
131 m_VideoWidget.SetTime(m_Progress.GetCurrent(), finished);
132
133 return super.OnChange(w, x, y, finished);
134 }
135
136 override bool OnClick(Widget w, int x, int y, int button)
137 {
138 if (w == m_PlayButton)
139 PlayVideo();
140 else if (w == m_PauseButton)
141 PauseVideo();
142 else if (w == m_StopButton)
143 StopVideo();
144 else if (w == m_OnceButton)
145 OnceVideo();
146 else if (w == m_RepeatButton)
147 RepeatVideo();
148 else if (w == m_LoadButton)
150 else if (w == m_Progress)
151 {
152 Print(x);
153 Print(y);
154 Print(button);
155 }
156 else if (w.GetUserID() == 333)
157 {
158 string name;
159 ButtonWidget.Cast(w).GetText(name);
162 }
163
164 return super.OnClick(w, x, y, button);
165 }
166
167 protected void OnPlaybackStart()
168 {
169 m_PlayButton.Show(false);
170 m_PauseButton.Show(true);
171
172 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateCurrentTime, 0, true);
173 }
174
175 protected void OnPlaybackStop()
176 {
177 m_PlayButton.Show(true);
178 m_PauseButton.Show(false);
179
181
182 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(UpdateCurrentTime);
183 }
184
185 protected void OnBufferingStart()
186 {
187 m_Buffering.Show(true);
188 }
189
190 protected void OnBufferingEnd()
191 {
192 m_Buffering.Show(false);
193 }
194
196 {
197 if (!m_LoadVideo.IsVisible())
199 else
200 {
201 Widget child = m_LoadVideo.GetChildren();
202
203 while (child)
204 {
205 Widget c = child;
206 child = child.GetSibling();
207 c.Unlink();
208 }
209 }
210
211 m_LoadVideo.Show(!m_LoadVideo.IsVisible());
212 }
213
214 void LoadVideo(string videoPath)
215 {
216 string path;
217#ifdef PLATFORM_WINDOWS
218 path = ".\\video\\";
219#endif
220#ifdef PLATFORM_PS4
221 path = "/app0/video/";
222#endif
223#ifdef PLATFORM_XBOX
224 path = "G:\\video\\";
225#endif
226
227 m_VideoWidget.Load(path + videoPath, m_VideoWidget.IsLooping());
228
229 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateTotalTime, 0, true);
230 }
231
233 {
234 m_VideoWidget.Play();
235 }
236
238 {
239 m_VideoWidget.Pause();
240 }
241
243 {
244 m_VideoWidget.Stop();
245 m_PlayButton.Show(true);
246 m_PauseButton.Show(false);
247 }
248
250 {
251 m_VideoWidget.SetLooping(false);
252 m_OnceButton.Show(false);
253 m_RepeatButton.Show(true);
254 }
255
257 {
258 m_VideoWidget.SetLooping(true);
259 m_RepeatButton.Show(false);
260 m_OnceButton.Show(true);
261 }
262
264 {
265 m_VideoWidget.Unload();
266 }
267}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Icon x
Icon y
Widget m_Root
Definition SizeToChild.c:85
struct that keeps Time relevant information for future formatting
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void VideoPlayer(Widget parent)
Definition VideoPlayer.c:24
void CreateVideoLoadingEntry(string entryName)
Definition VideoPlayer.c:92
override bool OnChange(Widget w, int x, int y, bool finished)
GridSpacerWidget m_LoadVideo
Definition VideoPlayer.c:14
void LoadVideo(string videoPath)
override bool OnClick(Widget w, int x, int y, int button)
void UpdateTime(TextWidget widget, int time)
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
proto native void CloseFindFile(FindFileHandle handle)
enum FindFileFlags FindFile(string pattern, out string fileName, out FileAttr fileAttributes, FindFileFlags flags)
FindFileFlags
Definition EnSystem.c:514
proto bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes)
FileAttr
Definition EnSystem.c:506
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8
VideoCallback
Definition EnWidgets.c:531