2023-02-22 01:58:15 +00:00
|
|
|
package funkin.graphics.video;
|
2021-04-18 03:19:33 +00:00
|
|
|
|
|
|
|
import flixel.FlxBasic;
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
import openfl.events.NetStatusEvent;
|
|
|
|
import openfl.media.Video;
|
|
|
|
import openfl.net.NetConnection;
|
|
|
|
import openfl.net.NetStream;
|
|
|
|
|
2023-02-22 01:58:15 +00:00
|
|
|
/**
|
|
|
|
* Plays a video via a NetStream. Only works on HTML5.
|
|
|
|
*/
|
2021-04-18 03:19:33 +00:00
|
|
|
class FlxVideo extends FlxBasic
|
|
|
|
{
|
2023-01-23 03:25:45 +00:00
|
|
|
var video:Video;
|
|
|
|
var netStream:NetStream;
|
|
|
|
|
|
|
|
public var finishCallback:Void->Void;
|
|
|
|
|
|
|
|
/**
|
2023-06-08 20:30:45 +00:00
|
|
|
* Doesn't actually interact with Flixel shit, only just a pleasant to use class
|
2023-01-23 03:25:45 +00:00
|
|
|
*/
|
2023-06-15 04:30:01 +00:00
|
|
|
public function new(videoPath:String)
|
2023-01-23 03:25:45 +00:00
|
|
|
{
|
|
|
|
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 04:30:01 +00:00
|
|
|
netStream.play(videoPath);
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-18 03:19:33 +00:00
|
|
|
}
|