Funkin/source/funkin/graphics/video/FlxVideo.hx

64 lines
1.5 KiB
Haxe
Raw Normal View History

package funkin.graphics.video;
2021-04-17 23:19:33 -04:00
import flixel.FlxBasic;
import flixel.FlxSprite;
import openfl.events.NetStatusEvent;
import openfl.media.Video;
import openfl.net.NetConnection;
import openfl.net.NetStream;
/**
* Plays a video via a NetStream. Only works on HTML5.
* This does NOT replace hxCodec, nor does hxCodec replace this. hxCodec only works on desktop and does not work on HTML5!
*/
2021-04-17 23:19:33 -04:00
class FlxVideo extends FlxBasic
{
var video:Video;
var netStream:NetStream;
public var finishCallback:Void->Void;
/**
2023-06-08 16:30:45 -04:00
* Doesn't actually interact with Flixel shit, only just a pleasant to use class
*/
2023-06-15 00:30:01 -04:00
public function new(videoPath: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);
2023-06-15 00:30:01 -04:00
netStream.play(videoPath);
}
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;
}
function netConnection_onNetStatus(event:NetStatusEvent):Void
{
if (event.info.code == 'NetStream.Play.Complete') finishVideo();
}
2021-04-17 23:19:33 -04:00
}