1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-14 02:42:55 +00:00
Funkin/source/FlxVideo.hx

62 lines
1.3 KiB
Haxe
Raw Normal View History

2021-04-18 03:19:33 +00:00
package;
import flixel.FlxBasic;
import flixel.FlxSprite;
import openfl.events.NetStatusEvent;
import openfl.media.Video;
import openfl.net.NetConnection;
import openfl.net.NetStream;
class FlxVideo extends FlxBasic
{
var video:Video;
var netStream:NetStream;
public var finishCallback:Void->Void;
/**
* Doesn't actually interact with Flixel shit, only just a pleasant to use class
*/
public function new(vidSrc:String)
{
super();
video = new Video();
video.x = 0;
video.y = 0;
FlxG.addChildBelowMouse(video);
var netConnection = new NetConnection();
netConnection.connect(null);
netStream = new NetStream(netConnection);
netStream.client = {onMetaData: client_onMetaData};
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnection_onNetStatus);
netStream.play(Paths.file(vidSrc));
}
public function finishVideo():Void
{
netStream.dispose();
FlxG.removeChild(video);
if (finishCallback != null)
finishCallback();
}
public function client_onMetaData(metaData:Dynamic)
{
video.attachNetStream(netStream);
video.width = FlxG.width;
video.height = FlxG.height;
}
private function netConnection_onNetStatus(event:NetStatusEvent):Void
{
if (event.info.code == 'NetStream.Play.Complete')
finishVideo();
}
}