1class VideoPlayer
extends ScriptedWidgetEventHandler
5 protected ButtonWidget m_PlayButton;
6 protected ButtonWidget m_PauseButton;
8 protected ButtonWidget m_StopButton;
10 protected ButtonWidget m_OnceButton;
11 protected ButtonWidget m_RepeatButton;
13 protected ButtonWidget m_LoadButton;
14 protected GridSpacerWidget m_LoadVideo;
16 protected SliderWidget m_Progress;
18 protected TextWidget m_CurrentTime;
19 protected TextWidget m_TotalTime;
21 protected ImageWidget m_Buffering;
22 VideoWidget m_VideoWidget;
24 void VideoPlayer(Widget parent)
26 m_Root =
g_Game.GetWorkspace().CreateWidgets(
"gui/layouts/new_ui/video_player.layout", parent);
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"));
47 m_OnceButton = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"vp_OnceButton"));
48 m_RepeatButton = ButtonWidget.Cast(
m_Root.FindAnyWidget(
"vp_RepeatButton"));
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);
54 m_Progress = SliderWidget.Cast(
m_Root.FindAnyWidget(
"vp_Progress"));
55 m_Progress.SetCurrent(0);
57 m_CurrentTime = TextWidget.Cast(
m_Root.FindAnyWidget(
"vp_CurrentTime"));
58 m_TotalTime = TextWidget.Cast(
m_Root.FindAnyWidget(
"vp_TotalTime"));
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"));
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);
74 private void InitVideoLoading()
76 string path =
"video\\*";
85 CreateVideoLoadingEntry(fileName);
90 CreateVideoLoadingEntry(fileName);
96 private void CreateVideoLoadingEntry(
string entryName)
98 Widget entry =
g_Game.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);
104 private void UpdateCurrentTime()
106 int time = m_VideoWidget.GetTime();
107 UpdateTime(m_CurrentTime, time);
109 m_Progress.SetCurrent(time);
113 private void UpdateTotalTime()
115 int time = m_VideoWidget.GetTotalTime();
119 UpdateTime(m_TotalTime, time);
120 m_Progress.SetMinMax(0, time);
125 private void UpdateTime(TextWidget widget,
int time)
127 FullTimeData timeData =
new FullTimeData();
128 TimeConversions.ConvertSecondsToFullTime(time / 1000, timeData);
129 widget.SetText(timeData.FormatedAsTimestamp());
132 override bool OnChange(Widget w,
int x,
int y,
bool finished)
136 m_VideoWidget.SetTime(m_Progress.GetCurrent(), finished);
139 return super.OnChange(w,
x,
y, finished);
142 override bool OnClick(Widget w,
int x,
int y,
int button)
144 if (w == m_PlayButton)
148 else if (w == m_PauseButton)
152 else if (w == m_StopButton)
156 else if (w == m_OnceButton)
160 else if (w == m_RepeatButton)
164 else if (w == m_LoadButton)
166 ToggleVideoSelection();
168 else if (w == m_Progress)
174 else if (w.GetUserID() == 333)
177 ButtonWidget.Cast(w).GetText(
name);
179 ToggleVideoSelection();
182 return super.OnClick(w,
x,
y, button);
185 protected void OnPlaybackStart()
187 m_PlayButton.Show(
false);
188 m_PauseButton.Show(
true);
193 protected void OnPlaybackStop()
195 m_PlayButton.Show(
true);
196 m_PauseButton.Show(
false);
203 protected void OnBufferingStart()
205 m_Buffering.Show(
true);
208 protected void OnBufferingEnd()
210 m_Buffering.Show(
false);
213 void ToggleVideoSelection()
215 if (!m_LoadVideo.IsVisible())
221 Widget child = m_LoadVideo.GetChildren();
226 child = child.GetSibling();
231 m_LoadVideo.Show(!m_LoadVideo.IsVisible());
234 void LoadVideo(
string videoPath)
237 #ifdef PLATFORM_WINDOWS
240 #ifdef PLATFORM_MSSTORE
244 path =
"/app0/video/";
247 path =
"G:\\video\\";
250 m_VideoWidget.Load(
path + videoPath, m_VideoWidget.IsLooping());
257 m_VideoWidget.Play();
262 m_VideoWidget.Pause();
267 m_VideoWidget.Stop();
268 m_PlayButton.Show(
true);
269 m_PauseButton.Show(
false);
274 m_VideoWidget.SetLooping(
false);
275 m_OnceButton.Show(
false);
276 m_RepeatButton.Show(
true);
281 m_VideoWidget.SetLooping(
true);
282 m_RepeatButton.Show(
false);
283 m_OnceButton.Show(
true);
288 m_VideoWidget.Unload();
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
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)
proto bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes)
override bool OnChange(Widget w, int x, int y, bool finished)