diff --git a/hmm.json b/hmm.json index 50d9475f..91b86175 100644 --- a/hmm.json +++ b/hmm.json @@ -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", diff --git a/source/funkin/game/cutscenes/MP4Handler.hx b/source/funkin/game/cutscenes/MP4Handler.hx deleted file mode 100644 index 6d10b9f6..00000000 --- a/source/funkin/game/cutscenes/MP4Handler.hx +++ /dev/null @@ -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 = null; - public var canvasHeight:Null = 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 \ No newline at end of file diff --git a/source/funkin/game/cutscenes/VideoCutscene.hx b/source/funkin/game/cutscenes/VideoCutscene.hx index 0a8031e6..18be35fc 100644 --- a/source/funkin/game/cutscenes/VideoCutscene.hx +++ b/source/funkin/game/cutscenes/VideoCutscene.hx @@ -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