Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for video cutscenes in polymod using hxvlc. #2639

Closed
wants to merge 16 commits into from
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@
"args": ["-debug", "-DANIMDEBUG", "-DFORCE_DEBUG_VERSION"]
},
{
"label": "Windows / Debug (Debug hxCodec)",
"label": "Windows / Debug (Debug hxvlc)",
"target": "windows",
"args": ["-debug", "-DHXC_LIBVLC_LOGGING", "-DFORCE_DEBUG_VERSION"]
"args": ["-debug", "-DHXVLC_LOGGING", "-DHXVLC_VERBOSE=2", "-DFORCE_DEBUG_VERSION"]
},
{
"label": "HashLink / Debug (Straight to Animation Editor)",
Expand Down
2 changes: 1 addition & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<haxelib name="flixel-text-input" /> <!-- Improved text field rendering for HaxeUI -->
<haxelib name="polymod" /> <!-- Modding framework -->
<haxelib name="flxanimate" /> <!-- Texture atlas rendering -->
<haxelib name="hxCodec" if="desktop" unless="hl" /> <!-- Video playback -->
<haxelib name="hxvlc" if="desktop || mobile" unless="hl" /> <!-- Video playback -->
<haxelib name="funkin.vis"/>


Expand Down
8 changes: 3 additions & 5 deletions hmm.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@
"version": "2.5.0"
},
{
"name": "hxCodec",
"type": "git",
"dir": null,
"ref": "61b98a7a353b7f529a8fec84ed9afc919a2dffdd",
"url": "https://github.com/FunkinCrew/hxCodec"
"name": "hxvlc",
"type": "haxelib",
"version": "1.8.5"
},
{
"name": "hxcpp",
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/graphics/video/FlxVideo.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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!
* This does NOT replace hxvlc, nor does hxvlc replace this.
* hxvlc only works on desktop and does not work on HTML5!
*/
class FlxVideo extends FunkinSprite
{
Expand Down
39 changes: 22 additions & 17 deletions source/funkin/play/cutscene/VideoCutscene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import flixel.util.FlxTimer;
#if html5
import funkin.graphics.video.FlxVideo;
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
#if hxvlc
import hxvlc.flixel.FlxVideoSprite;
#end

/**
Expand All @@ -25,7 +25,7 @@ class VideoCutscene
#if html5
static var vid:FlxVideo;
#end
#if hxCodec
#if hxvlc
static var vid:FlxVideoSprite;
#end

Expand Down Expand Up @@ -93,16 +93,16 @@ class VideoCutscene

#if html5
playVideoHTML5(rawFilePath);
#elseif hxCodec
playVideoNative(rawFilePath);
#elseif hxvlc
playVideoNative(filePath);
#else
throw "No video support for this platform!";
#end
}

public static function isPlaying():Bool
{
#if (html5 || hxCodec)
#if (html5 || hxvlc)
return vid != null;
#else
return false;
Expand Down Expand Up @@ -135,7 +135,7 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
static function playVideoNative(filePath:String):Void
{
// Video displays OVER the FlxState.
Expand All @@ -152,18 +152,22 @@ class VideoCutscene
PlayState.instance.add(vid);

PlayState.instance.refresh();
vid.play(filePath, false);

// Resize videos bigger or smaller than the screen.
vid.bitmap.onTextureSetup.add(() -> {
vid.bitmap.onFormatSetup.add(() -> {
vid.setGraphicSize(FlxG.width, FlxG.height);
vid.updateHitbox();
vid.x = 0;
vid.y = 0;
// vid.scale.set(0.5, 0.5);
});

onVideoStarted.dispatch();
if (vid.load(openfl.Assets.getBytes(filePath)))
{
vid.play();

onVideoStarted.dispatch();
}
}
else
{
Expand All @@ -182,11 +186,12 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
// Seek to the start of the video.
vid.bitmap.time = 0;

if (resume)
{
// Resume the video if it was paused.
Expand All @@ -208,7 +213,7 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
vid.pause();
Expand All @@ -227,7 +232,7 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
vid.visible = false;
Expand All @@ -246,7 +251,7 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
vid.visible = true;
Expand All @@ -265,7 +270,7 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
vid.resume();
Expand All @@ -292,15 +297,15 @@ class VideoCutscene
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
vid.stop();
PlayState.instance.remove(vid);
}
#end

#if (html5 || hxCodec)
#if (html5 || hxvlc)
vid.destroy();
vid = null;
#end
Expand Down
23 changes: 15 additions & 8 deletions source/funkin/ui/title/AttractState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package funkin.ui.title;
#if html5
import funkin.graphics.video.FlxVideo;
#end
#if hxCodec
import hxcodec.flixel.FlxVideoSprite;
#if hxvlc
import hxvlc.flixel.FlxVideoSprite;
#end
import funkin.ui.MusicBeatState;

Expand All @@ -17,7 +17,13 @@ import funkin.ui.MusicBeatState;
*/
class AttractState extends MusicBeatState
{
#if html5
static final ATTRACT_VIDEO_PATH:String = Paths.stripLibrary(Paths.videos('toyCommercial'));
#end

#if hxvlc
static final ATTRACT_VIDEO_PATH:String = Paths.videos('toyCommercial');
#end

public override function create():Void
{
Expand All @@ -33,7 +39,7 @@ class AttractState extends MusicBeatState
playVideoHTML5(ATTRACT_VIDEO_PATH);
#end

#if hxCodec
#if hxvlc
trace('Playing native video ${ATTRACT_VIDEO_PATH}');
playVideoNative(ATTRACT_VIDEO_PATH);
#end
Expand Down Expand Up @@ -61,7 +67,7 @@ class AttractState extends MusicBeatState
}
#end

#if hxCodec
#if hxvlc
var vid:FlxVideoSprite;

function playVideoNative(filePath:String):Void
Expand All @@ -73,9 +79,10 @@ class AttractState extends MusicBeatState
{
vid.zIndex = 0;
vid.bitmap.onEndReached.add(onAttractEnd);

add(vid);
vid.play(filePath, false);

if (vid.load(openfl.Assets.getBytes(filePath)))
vid.play();
}
else
{
Expand Down Expand Up @@ -108,15 +115,15 @@ class AttractState extends MusicBeatState
}
#end

#if hxCodec
#if hxvlc
if (vid != null)
{
vid.stop();
remove(vid);
}
#end

#if (html5 || hxCodec)
#if (html5 || hxvlc)
vid.destroy();
vid = null;
#end
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<haxelib name="haxeui-flixel" /> <!-- Integrate HaxeUI with Flixel -->
<haxelib name="polymod" /> <!-- Modding framework -->
<haxelib name="flxanimate" /> <!-- Texture atlas rendering -->
<haxelib name="hxCodec" /> <!-- Video playback -->
<haxelib name="hxvlc" /> <!-- Video playback -->
<haxelib name="thx.semver" /> <!-- Semantic version handling -->
<haxelib name="json2object" /> <!-- JSON parsing -->

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-lib haxeui-core
-lib haxeui-flixel
-lib flxanimate
-lib hxCodec
-lib hxvlc
-lib thx.semver
-lib json2object
-lib tink_json
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test.hxml-old
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
-lib haxeui-core
-lib haxeui-flixel
-lib flxanimate
-lib hxCodec
-lib hxvlc
-lib thx.semver
-lib json2object
-lib tink_json
Expand Down Expand Up @@ -48,7 +48,7 @@
-lib haxeui-flixel
-lib polymod
-lib flxanimate
-lib hxCodec
-lib hxvlc
-lib thx.semver
-lib json2object
-lib tink_json
Expand Down
Loading