forked from ZHyproX/Indie-Cross-Master
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVideoHandler.hx
More file actions
195 lines (159 loc) · 3.39 KB
/
Copy pathVideoHandler.hx
File metadata and controls
195 lines (159 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//This was made by GWebDev lol btw this uses actuate
package;
import motion.Actuate;
import openfl.display.Sprite;
import openfl.events.AsyncErrorEvent;
import openfl.events.MouseEvent;
import openfl.events.NetStatusEvent;
import openfl.media.Video;
import openfl.net.NetConnection;
import openfl.net.NetStream;
import flixel.FlxG;
using StringTools;
class VideoHandler
{
public var netStream:NetStream;
public var video:Video;
public var isReady:Bool = false;
public var addOverlay:Bool = false;
public var vidPath:String = "";
public var ignoreShit:Bool = false;
public function new()
{
isReady = false;
}
public function source(?vPath:String):Void
{
if (vPath != null && vPath.length > 0)
{
vidPath = vPath;
}
}
public function init1():Void
{
isReady = false;
video = new Video();
video.visible = false;
}
public function init2():Void
{
#if web
var netConnection = new NetConnection ();
netConnection.connect (null);
netStream = new NetStream (netConnection);
netStream.client = { onMetaData: client_onMetaData };
netStream.addEventListener (AsyncErrorEvent.ASYNC_ERROR, netStream_onAsyncError);
netConnection.addEventListener (NetStatusEvent.NET_STATUS, netConnection_onNetStatus);
netConnection.addEventListener (NetStatusEvent.NET_STATUS, onPlay);
netConnection.addEventListener (NetStatusEvent.NET_STATUS, onEnd);
#end
}
public function client_onMetaData (metaData:Dynamic) {
video.attachNetStream (netStream);
video.width = FlxG.width;
video.height = FlxG.height;
}
public function netStream_onAsyncError (event:AsyncErrorEvent):Void {
trace ("Error loading video");
}
public function netConnection_onNetStatus (event:NetStatusEvent):Void {
trace (event.info.code);
}
public function play():Void
{
#if web
ignoreShit = true;
netStream.close();
init2();
netStream.play(vidPath);
ignoreShit = false;
#end
trace(vidPath);
}
public function stop():Void
{
netStream.close();
onStop();
}
public function restart():Void
{
play();
onRestart();
}
public function update(elapsed:Float):Void
{
video.x = GlobalVideo.calc(0);
video.y = GlobalVideo.calc(1);
video.width = GlobalVideo.calc(2);
video.height = GlobalVideo.calc(3);
}
public var stopped:Bool = false;
public var restarted:Bool = false;
public var played:Bool = false;
public var ended:Bool = false;
public var paused:Bool = false;
public function pause():Void
{
netStream.pause();
paused = true;
}
public function resume():Void
{
netStream.resume();
paused = false;
}
public function togglePause():Void
{
if (paused)
{
resume();
} else {
pause();
}
}
public function clearPause():Void
{
paused = false;
}
public function onStop():Void
{
if (!ignoreShit)
{
stopped = true;
}
}
public function onRestart():Void
{
restarted = true;
}
public function onPlay(event:NetStatusEvent):Void
{
if (event.info.code == "NetStream.Play.Start")
{
played = true;
}
}
public function onEnd(event:NetStatusEvent):Void
{
if (event.info.code == "NetStream.Play.Complete")
{
ended = true;
}
}
public function alpha():Void
{
video.alpha = GlobalVideo.daAlpha1;
}
public function unalpha():Void
{
video.alpha = GlobalVideo.daAlpha2;
}
public function hide():Void
{
video.visible = false;
}
public function show():Void
{
video.visible = true;
}
}