forked from grafexteam/fnf-grafex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoState.hx
233 lines (181 loc) · 4.65 KB
/
VideoState.hx
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package;
import flixel.FlxState;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxSubState;
import flixel.text.FlxText;
import flixel.util.FlxColor;
import flixel.util.FlxTimer;
import lime.app.Application;
import flixel.system.FlxSound;
import openfl.utils.Assets;
import openfl.utils.AssetType;
import flixel.FlxCamera;
import flixel.addons.transition.FlxTransitionableState;
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 vlc.VlcBitmap;
import openfl.events.Event;
import StoryMenuState;
import PlayState;
import openfl.Lib;
using StringTools;
class GameDimensions
{
public static var width:Int = 1280;
public static var height:Int = 720;
}
// Made by BrigthFyr
class MP4Handler
{
public static var video:Video;
public static var netStream:NetStream;
public static var finishCallback:FlxState;
public var sprite:FlxSprite;
#if desktop
public static var vlcBitmap:VlcBitmap;
#end
public function new()
{
FlxG.autoPause = false;
if (FlxG.sound.music != null)
{
FlxG.sound.music.stop();
}
}
public function playMP4(path:String, callback:FlxState, ?outputTo:FlxSprite = null, ?repeat:Bool = false, ?isWindow:Bool = false, ?isFullscreen:Bool = false):Void
{
#if html5
FlxG.autoPause = false;
if (FlxG.sound.music != null)
{
FlxG.sound.music.stop();
}
finishCallback = callback;
video = new Video();
video.x = 0;
video.y = 0;
FlxG.addChildBelowMouse(video);
var nc = new NetConnection();
nc.connect(null);
netStream = new NetStream(nc);
netStream.client = {onMetaData: client_onMetaData};
nc.addEventListener("netStatus", netConnection_onNetStatus);
netStream.play(path);
#else
finishCallback = callback;
vlcBitmap = new VlcBitmap();
vlcBitmap.set_height(FlxG.stage.stageHeight);
vlcBitmap.set_width(FlxG.stage.stageHeight * (16 / 9));
trace("Setting width to " + FlxG.stage.stageHeight * (16 / 9));
trace("Setting height to " + FlxG.stage.stageHeight);
vlcBitmap.onVideoReady = onVLCVideoReady;
vlcBitmap.onComplete = onVLCComplete;
vlcBitmap.onError = onVLCError;
FlxG.stage.addEventListener(Event.ENTER_FRAME, update);
if (repeat)
vlcBitmap.repeat = -1;
else
vlcBitmap.repeat = 0;
vlcBitmap.inWindow = isWindow;
vlcBitmap.fullscreen = isFullscreen;
FlxG.addChildBelowMouse(vlcBitmap);
vlcBitmap.play(checkFile(path));
if (outputTo != null)
{
// lol this is bad kek
vlcBitmap.alpha = 0;
sprite = outputTo;
}
#end
}
#if desktop
function checkFile(fileName:String):String
{
var pDir = "";
var appDir = "file:///" + Sys.getCwd() + "/";
if (fileName.indexOf(":") == -1) // Not a path
pDir = appDir;
else if (fileName.indexOf("file://") == -1 || fileName.indexOf("http") == -1) // C:, D: etc? ..missing "file:///" ?
pDir = "file:///";
return pDir + fileName;
}
/////////////////////////////////////////////////////////////////////////////////////
function onVLCVideoReady()
{
trace("video loaded!");
if (sprite != null)
sprite.loadGraphic(vlcBitmap.bitmapData);
}
public function onVLCComplete()
{
vlcBitmap.stop();
// Clean player, just in case! Actually no.
FlxG.camera.fade(FlxColor.BLACK, 0, false);
trace("Big, Big Chungus, Big Chungus!");
new FlxTimer().start(0.3, function (tmr:FlxTimer)
{
if (finishCallback != null)
{
LoadingState.loadAndSwitchState(finishCallback);
}
vlcBitmap.dispose();
if (FlxG.game.contains(vlcBitmap))
{
FlxG.game.removeChild(vlcBitmap);
}
});
}
function onVLCError()
{
if (finishCallback != null)
{
LoadingState.loadAndSwitchState(finishCallback);
}
}
function update(e:Event)
{
if (FlxG.keys.justPressed.ENTER || FlxG.keys.justPressed.SPACE)
{
if (vlcBitmap.isPlaying)
{
onVLCComplete();
}
}
vlcBitmap.volume = FlxG.sound.volume + 0.3; // shitty volume fix. then make it louder.
if (FlxG.sound.volume <= 0.1) vlcBitmap.volume = 0;
}
#end
/////////////////////////////////////////////////////////////////////////////////////
function client_onMetaData(path)
{
video.attachNetStream(netStream);
video.width = FlxG.width;
video.height = FlxG.height;
}
function netConnection_onNetStatus(path)
{
if (path.info.code == "NetStream.Play.Complete")
{
finishVideo();
}
}
function finishVideo()
{
netStream.dispose();
if (FlxG.game.contains(video))
{
FlxG.game.removeChild(video);
}
if (finishCallback != null)
{
LoadingState.loadAndSwitchState(finishCallback);
}
else
LoadingState.loadAndSwitchState(new MainMenuState());
}
}