new hxCodec

This commit is contained in:
lunarcleint
2023-06-25 17:53:27 -07:00
parent 6578f6c309
commit 32c8eab86e
3 changed files with 21 additions and 195 deletions
+5 -5
View File
@@ -1,5 +1,10 @@
{
"dependencies": [
{
"name": "hxCodec",
"type": "git",
"url": "https://github.com/polybiusproxy/hxCodec"
},
{
"name": "away3d",
"type": "haxelib",
@@ -41,11 +46,6 @@
"ref": "custom-classes",
"url": "https://www.github.com/FNF-CNE-Devs/hscript-improved"
},
{
"name": "hxCodec",
"type": "haxelib",
"version": "2.5.1"
},
{
"name": "hxcpp-debug-server",
"type": "haxelib",
-175
View File
@@ -1,175 +0,0 @@
package funkin.game.cutscenes;
#if VIDEO_CUTSCENES
import vlc.bitmap.VlcBitmap;
import flixel.util.FlxTimer;
import funkin.options.PlayerSettings;
import openfl.events.Event;
import flixel.FlxState;
class MP4Handler
{
public var finishCallback:Void->Void;
public var stateCallback:FlxState;
public var bitmap:VlcBitmap;
public var sprite:FlxSprite;
public var canvasWidth:Null<Int> = null;
public var canvasHeight:Null<Int> = null;
public var fillScreen:Bool;
public var skippable:Bool = true;
public function new()
{
//FlxG.autoPause = false;
}
public function playMP4(path:String, ?repeat:Bool = false, ?outputTo:FlxSprite = null, ?isWindow:Bool = false, ?isFullscreen:Bool = false,
?midSong:Bool = false):Void
{
if (!midSong)
{
if (FlxG.sound.music != null)
{
FlxG.sound.music.stop();
}
}
bitmap = new VlcBitmap();
if (FlxG.stage.stageHeight / 9 < FlxG.stage.stageWidth / 16)
{
bitmap.set_width(FlxG.stage.stageHeight * (16 / 9));
bitmap.set_height(FlxG.stage.stageHeight);
}
else
{
bitmap.set_width(FlxG.stage.stageWidth);
bitmap.set_height(FlxG.stage.stageWidth / (16 / 9));
}
bitmap.onVideoReady = onVLCVideoReady;
bitmap.onComplete = onVLCComplete;
bitmap.onError = onVLCError;
FlxG.stage.addEventListener(Event.ENTER_FRAME, update);
if (repeat)
bitmap.repeat = -1;
else
bitmap.repeat = 0;
// bitmap.inWindow = isWindow;
// bitmap.fullscreen = isFullscreen;
FlxG.addChildBelowMouse(bitmap);
bitmap.play(checkFile(path));
if (outputTo != null)
{
// lol this is bad kek
bitmap.alpha = 0;
sprite = outputTo;
}
}
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(bitmap.bitmapData);
if (canvasWidth != null && canvasHeight != null) {
sprite.setGraphicSize(canvasWidth, canvasHeight);
sprite.updateHitbox();
var r = (fillScreen ? Math.max : Math.min)(sprite.scale.x, sprite.scale.y);
sprite.scale.set(r, r); // lol
}
}
}
public function onVLCComplete()
{
bitmap.stop();
new FlxTimer().start(0.3, function(tmr:FlxTimer)
{
if (finishCallback != null)
{
finishCallback();
}
else if (stateCallback != null)
{
FlxG.switchState(stateCallback);
}
bitmap.dispose();
if (FlxG.game.contains(bitmap))
{
FlxG.game.removeChild(bitmap);
}
});
}
public function kill()
{
bitmap.stop();
if (finishCallback != null)
{
finishCallback();
}
bitmap.visible = false;
}
function onVLCError()
{
if (finishCallback != null)
{
finishCallback();
}
else if (stateCallback != null)
{
FlxG.switchState(stateCallback);
}
}
function update(e:Event)
{
if (PlayerSettings.player1.controls.ACCEPT && skippable)
{
if (bitmap.isPlaying)
{
onVLCComplete();
}
}
bitmap.volume = FlxG.sound.volume + 0.3; // shitty volume fix. then make it louder.
if (FlxG.sound.volume <= 0.1 || FlxG.sound.muted)
bitmap.volume = 0;
}
}
#end
+16 -15
View File
@@ -8,7 +8,9 @@ import sys.io.File;
#end
import funkin.backend.FunkinText;
import haxe.xml.Access;
#if VIDEO_CUTSCENES
import hxcodec.flixel.FlxVideo;
#end
/**
* Substate made for video cutscenes. To use it in a scripted cutscene, call `startVideo`.
@@ -19,8 +21,8 @@ class VideoCutscene extends Cutscene {
var localPath:String;
#if VIDEO_CUTSCENES
var video:MP4Handler;
var videoSprite:FlxSprite;
var video:FlxVideo;
public var skippable:Bool = true;
#end
var cutsceneCamera:FlxCamera;
@@ -50,14 +52,9 @@ class VideoCutscene extends Cutscene {
#if VIDEO_CUTSCENES
parseSubtitles();
video = new MP4Handler();
video.finishCallback = close;
video.canvasWidth = cutsceneCamera.width;
video.canvasHeight = cutsceneCamera.height;
videoSprite = new FlxSprite();
videoSprite.cameras = [cutsceneCamera];
videoSprite.antialiasing = true;
video = new FlxVideo();
video.onEndReached.add(close);
video.onEndReached.add(video.dispose);
bg = new FlxSprite(0, FlxG.height * 0.85).makeGraphic(1, 1, 0xFF000000);
bg.alpha = 0.5;
@@ -88,9 +85,8 @@ class VideoCutscene extends Cutscene {
videoReady = true;
});
} else {
video.playMP4(localPath, false, videoSprite);
video.play(localPath);
}
add(videoSprite);
add(bg);
add(subtitle);
#end
@@ -164,18 +160,23 @@ class VideoCutscene extends Cutscene {
#if VIDEO_CUTSCENES
if (videoReady) {
videoReady = false;
video.playMP4(localPath, false, videoSprite);
video.play(localPath);
if (loadingBackdrop != null)
loadingBackdrop.visible = false;
}
@:privateAccess
var time = video.bitmap.getTime();
var time = video.time;
while (subtitles.length > 0 && subtitles[0].time < time)
setSubtitle(subtitles.shift());
if (loadingBackdrop != null) {
loadingBackdrop.x -= elapsed * FlxG.width * 0.5;
}
if (skippable && video.isPlaying && controls.ACCEPT) {
video.stop();
video.dispose();
close();
}
#else
close();
#end