Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
videoplayer.c
Go to the documentation of this file.
1 class VideoPlayer extends ScriptedWidgetEventHandler
2 {
3  protected Widget m_Root;
4 
5  protected ButtonWidget m_PlayButton;
6  protected ButtonWidget m_PauseButton;
7 
8  protected ButtonWidget m_StopButton;
9 
10  protected ButtonWidget m_OnceButton;
11  protected ButtonWidget m_RepeatButton;
12 
13  protected ButtonWidget m_LoadButton;
14  protected GridSpacerWidget m_LoadVideo;
15 
16  protected SliderWidget m_Progress;
17 
18  protected TextWidget m_CurrentTime;
19  protected TextWidget m_TotalTime;
20 
21  protected ImageWidget m_Buffering;
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 
32  void ~VideoPlayer()
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;
79  FileAttr fileAttr;
80 
81  FindFileHandle handle = FindFile(path, fileName, fileAttr, FindFileFlags.DIRECTORIES);
82 
83  if (fileName != "")
84  {
85  CreateVideoLoadingEntry(fileName);
86  }
87 
88  while (FindNextFile(handle, fileName, fileAttr))
89  {
90  CreateVideoLoadingEntry(fileName);
91  }
92 
93  CloseFindFile(handle);
94  }
95 
96  private void CreateVideoLoadingEntry(string entryName)
97  {
98  Widget entry = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/video_player_entry.layout", m_LoadVideo);
99  ButtonWidget entryButton = ButtonWidget.Cast(entry.GetChildren());
100  entryButton.SetText(entryName);
101  entryButton.SetUserID(333);
102  }
103 
104  private void UpdateCurrentTime()
105  {
106  int time = m_VideoWidget.GetTime();
107  UpdateTime(m_CurrentTime, time);
108 
109  m_Progress.SetCurrent(time);
110  }
111 
112  // This can be an async op
113  private void UpdateTotalTime()
114  {
115  int time = m_VideoWidget.GetTotalTime();
116 
117  if (time != 0)
118  {
119  UpdateTime(m_TotalTime, time);
120  m_Progress.SetMinMax(0, time);
121  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(UpdateTotalTime);
122  }
123  }
124 
125  private void UpdateTime(TextWidget widget, int time)
126  {
127  FullTimeData timeData = new FullTimeData();
128  TimeConversions.ConvertSecondsToFullTime(time / 1000, timeData);
129  widget.SetText(timeData.FormatedAsTimestamp());
130  }
131 
132  override bool OnChange(Widget w, int x, int y, bool finished)
133  {
134  if (w == m_Progress)
135  {
136  m_VideoWidget.SetTime(m_Progress.GetCurrent(), finished);
137  }
138 
139  return super.OnChange(w, x, y, finished);
140  }
141 
142  override bool OnClick(Widget w, int x, int y, int button)
143  {
144  if (w == m_PlayButton)
145  {
146  PlayVideo();
147  }
148  else if (w == m_PauseButton)
149  {
150  PauseVideo();
151  }
152  else if (w == m_StopButton)
153  {
154  StopVideo();
155  }
156  else if (w == m_OnceButton)
157  {
158  OnceVideo();
159  }
160  else if (w == m_RepeatButton)
161  {
162  RepeatVideo();
163  }
164  else if (w == m_LoadButton)
165  {
166  ToggleVideoSelection();
167  }
168  else if (w == m_Progress)
169  {
170  Print(x);
171  Print(y);
172  Print(button);
173  }
174  else if (w.GetUserID() == 333)
175  {
176  string name;
177  ButtonWidget.Cast(w).GetText(name);
178  LoadVideo(name);
179  ToggleVideoSelection();
180  }
181 
182  return super.OnClick(w, x, y, button);
183  }
184 
185  protected void OnPlaybackStart()
186  {
187  m_PlayButton.Show(false);
188  m_PauseButton.Show(true);
189 
190  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateCurrentTime, 0, true);
191  }
192 
193  protected void OnPlaybackStop()
194  {
195  m_PlayButton.Show(true);
196  m_PauseButton.Show(false);
197 
198  UpdateCurrentTime();
199 
200  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(UpdateCurrentTime);
201  }
202 
203  protected void OnBufferingStart()
204  {
205  m_Buffering.Show(true);
206  }
207 
208  protected void OnBufferingEnd()
209  {
210  m_Buffering.Show(false);
211  }
212 
213  void ToggleVideoSelection()
214  {
215  if (!m_LoadVideo.IsVisible())
216  {
217  InitVideoLoading();
218  }
219  else
220  {
221  Widget child = m_LoadVideo.GetChildren();
222 
223  while (child)
224  {
225  Widget c = child;
226  child = child.GetSibling();
227  c.Unlink();
228  }
229  }
230 
231  m_LoadVideo.Show(!m_LoadVideo.IsVisible());
232  }
233 
234  void LoadVideo(string videoPath)
235  {
236  string path;
237  #ifdef PLATFORM_WINDOWS
238  path = ".\\video\\";
239  #endif
240  #ifdef PLATFORM_PS4
241  path = "/app0/video/";
242  #endif
243  #ifdef PLATFORM_XBOX
244  path = "G:\\video\\";
245  #endif
246 
247  m_VideoWidget.Load(path + videoPath, m_VideoWidget.IsLooping());
248 
249  GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateTotalTime, 0, true);
250  }
251 
252  void PlayVideo()
253  {
254  m_VideoWidget.Play();
255  }
256 
257  void PauseVideo()
258  {
259  m_VideoWidget.Pause();
260  }
261 
262  void StopVideo()
263  {
264  m_VideoWidget.Stop();
265  m_PlayButton.Show(true);
266  m_PauseButton.Show(false);
267  }
268 
269  void OnceVideo()
270  {
271  m_VideoWidget.SetLooping(false);
272  m_OnceButton.Show(false);
273  m_RepeatButton.Show(true);
274  }
275 
276  void RepeatVideo()
277  {
278  m_VideoWidget.SetLooping(true);
279  m_RepeatButton.Show(false);
280  m_OnceButton.Show(true);
281  }
282 
283  void KillVideo()
284  {
285  m_VideoWidget.Unload();
286  }
287 }
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
Show
proto native void Show(bool show, bool immedUpdate=true)
y
Icon y
Print
proto void Print(void var)
Prints content of variable to console/log.
FindNextFile
proto bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes)
FindFileHandle
int[] FindFileHandle
Definition: ensystem.c:503
VideoCallback
VideoCallback
Definition: enwidgets.c:530
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
FindFileFlags
FindFileFlags
Definition: ensystem.c:513
FindFile
enum FindFileFlags FindFile(string pattern, out string fileName, out FileAttr fileAttributes, FindFileFlags flags)
CloseFindFile
proto native void CloseFindFile(FindFileHandle handle)
FileAttr
FileAttr
Definition: ensystem.c:505
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
FullTimeData
struct that keeps Time relevant information for future formatting
Definition: timeconversions.c:4
OnChange
bool OnChange(Widget w, int x, int y, bool finished)
Definition: huddebug.c:336
Widget
Definition: enwidgets.c:189
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650
path
string path
Definition: optionselectormultistate.c:135