Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/funkin/util/flixel/sound/FlxPartialSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import lime.net.HTTPRequestHeader;
import openfl.media.Sound;
import openfl.utils.Assets;

using StringTools;
#if lime_vorbis
import lime.media.vorbis.VorbisFile;
#end

using StringTools;

class FlxPartialSound
{
Expand Down Expand Up @@ -208,6 +208,41 @@ class FlxPartialSound
#end // web/sys check
}

/**
* Similar to `partialLoadAndPlayFile`, except instead of percentages, it uses milliseconds as range values.
* @param path
* @param rangeStart what millisecond of the song should it start at
* @param rangeEnd what millisecond of the song should it end at
* @return Future<Sound>
*/
public static function partialLoadAndPlayFileRaw(path:String, ?rangeStart:Int = 0, ?rangeEnd:Int = 1000):Future<Sound>
{
return partialLoadFromFileRaw(path, rangeStart, rangeEnd).future.onComplete(function(sound:Sound)
{
FlxG.sound.play(sound);
});
}

/**
* Similar to `partialLoadFromFile`, except instead of percentages, it uses milliseconds as range values.
* @param path
* @param rangeStart what millisecond of the song should it start at
* @param rangeEnd what millisecond of the song should it end at
* @return Future<Sound>
*/
public static function partialLoadFromFileRaw(path:String, ?rangeStart:Int = 0, ?rangeEnd:Int = 1000, ?paddedIntro:Bool = false):Promise<Sound>
{
if (!Assets.exists(path))
{

FlxG.log.warn("Could not find audio file for partial playback: " + path);
return null;
}

var sound = Assets.getSound(path);
return partialLoadFromFile(path, rangeStart / sound.length, rangeEnd / sound.length, paddedIntro);
}

static function requestContentLength(path:String):Future<Int>
{
var promise:Promise<Int> = new Promise<Int>();
Expand Down