hxCodec icon indicating copy to clipboard operation
hxCodec copied to clipboard

Add video caching

Open DotWith opened this issue 3 years ago • 5 comments

Video caching is needed so it doesn't lag when creating the video

DotWith avatar Dec 07 '21 22:12 DotWith

Video caching was made but not pushed. Very experimental tho.

polybiusproxy avatar Dec 08 '21 10:12 polybiusproxy

Video caching is needed so it doesn't lag when creating the video

Actually, If you make a timer for 1 second before the video plays, it doesnt lag. Maybe a bit for really lowend but it works great just adding a FlxTimer for 1 sec before the video plays

TheRealJake12 avatar Dec 20 '21 01:12 TheRealJake12

Video caching was made but not pushed. Very experimental tho.

I know its experimental but how exactly would you do the video caching

TheRealJake12 avatar Dec 20 '21 21:12 TheRealJake12

Its a lazy method.

DotWith avatar Dec 21 '21 08:12 DotWith

Its a lazy method.

adding the timer or the video caching? the timer makes the videos load great. The FlxSprite lags out on my PC tho but for normal cutscenes just adding a small timer makes the perf a lot better

TheRealJake12 avatar Dec 22 '21 03:12 TheRealJake12

I made this function that would work. You use it right before super.create(), and I currently use it in CoolUtil.hx for Lunar Engine:

Precache Video Function

public static var loadingVideos:Array<String> = [];
public static var loadedVideos:Array<String> = [];

public static function precacheVideo(name:String):Void {
	#if VIDEOS_ALLOWED
	if(FileSystem.exists(Paths.video(name))) {
		if(!loadedVideos.contains(name)) {
			loadingVideos.push(name);
			var cache:VideoHandler = new VideoHandler();
			cache.canUseSound = false;
			cache.playVideo(Paths.video(name));
			cache.onOpening = function() {
				cache.stop();
				cache.dispose();
				loadedVideos.push(name);
				loadingVideos.remove(name);
			}
			FlxG.log.add('Video file has been cached: ' + name);
		} else {
			FlxG.log.add('Video file has already been cached: ' + name);
		}
	} else {
		FlxG.log.warn('Couldnt find video file: ' + name);
	}
	#else
	FlxG.log.warn('Platform not supported!');
	#end
}

KirbyKid256 avatar Feb 16 '23 12:02 KirbyKid256

noted. Thanks bro

TheRealJake12 avatar Feb 16 '23 23:02 TheRealJake12