1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-23 13:48:23 +00:00
Funkin/source/funkin/audio/FlxStreamSound.hx

50 lines
1.3 KiB
Haxe
Raw Normal View History

2023-08-31 05:56:35 +00:00
package funkin.audio;
import flash.media.Sound;
#if flash11
import flash.utils.ByteArray;
#end
import flixel.sound.FlxSound;
import flixel.system.FlxAssets.FlxSoundAsset;
import openfl.Assets;
#if (openfl >= "8.0.0")
import openfl.utils.AssetType;
#end
/**
* a FlxSound that just overrides loadEmbedded to allow for "streamed" sounds to load with better performance!
*/
class FlxStreamSound extends FlxSound
{
public function new()
{
super();
}
override public function loadEmbedded(EmbeddedSound:FlxSoundAsset, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void):FlxSound
{
if (EmbeddedSound == null) return this;
cleanup(true);
if ((EmbeddedSound is Sound))
{
_sound = EmbeddedSound;
}
else if ((EmbeddedSound is Class))
{
_sound = Type.createInstance(EmbeddedSound, []);
}
else if ((EmbeddedSound is String))
{
if (Assets.exists(EmbeddedSound, AssetType.SOUND)
|| Assets.exists(EmbeddedSound, AssetType.MUSIC)) _sound = Assets.getMusic(EmbeddedSound);
else
FlxG.log.error('Could not find a Sound asset with an ID of \'$EmbeddedSound\'.');
}
// NOTE: can't pull ID3 info from embedded sound currently
return init(Looped, AutoDestroy, OnComplete);
}
}