diff --git a/flixel/sound/FlxSound.hx b/flixel/sound/FlxSound.hx
index e087968790..ff7f3e8213 100644
--- a/flixel/sound/FlxSound.hx
+++ b/flixel/sound/FlxSound.hx
@@ -337,6 +337,8 @@ class FlxSound extends FlxBasic
/**
* One of the main setup functions for sounds, this function loads a sound from an embedded MP3.
*
+ * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension
+ *
* @param EmbeddedSound An embedded Class object representing an MP3 file.
* @param Looped Whether or not this sound should loop endlessly.
* @param AutoDestroy Whether or not this FlxSound instance should be destroyed when the sound finishes playing.
diff --git a/flixel/system/frontEnds/AssetFrontEnd.hx b/flixel/system/frontEnds/AssetFrontEnd.hx
index 6c2d7cf3a9..a6eea14cc2 100644
--- a/flixel/system/frontEnds/AssetFrontEnd.hx
+++ b/flixel/system/frontEnds/AssetFrontEnd.hx
@@ -85,6 +85,12 @@ class AssetFrontEnd
public function new () {}
#end
+ #if (FLX_DEFAULT_SOUND_EXT == "1" || FLX_NO_DEFAULT_SOUND_EXT)
+ public final defaultSoundExtension:String = #if flash ".mp3" #else ".ogg" #end;
+ #else
+ public final defaultSoundExtension:String = '.${haxe.macro.Compiler.getDefine("FLX_DEFAULT_SOUND_EXT")}';
+ #end
+
/**
* Used by methods like `getAsset`, `getBitmapData`, `getText`, their "unsafe" counterparts and
* the like to get assets synchronously. Can be set to a custom function to avoid the existing
@@ -231,6 +237,12 @@ class AssetFrontEnd
*/
public dynamic function exists(id:String, ?type:FlxAssetType)
{
+ #if FLX_DEFAULT_SOUND_EXT
+ // add file extension
+ if (type == SOUND)
+ id = addSoundExt(id);
+ #end
+
#if FLX_STANDARD_ASSETS_DIRECTORY
return Assets.exists(id, type.toOpenFlType());
#else
@@ -253,6 +265,12 @@ class AssetFrontEnd
*/
public dynamic function isLocal(id:String, ?type:FlxAssetType, useCache = true)
{
+ #if FLX_DEFAULT_SOUND_EXT
+ // add file extension
+ if (type == SOUND)
+ id = addSoundExt(id);
+ #end
+
#if FLX_STANDARD_ASSETS_DIRECTORY
return Assets.isLocal(id, type.toOpenFlType(), useCache);
#else
@@ -327,11 +345,13 @@ class AssetFrontEnd
*/
public inline function getSoundUnsafe(id:String, useCache = true):Sound
{
- return cast getAssetUnsafe(id, SOUND, useCache);
+ return cast getAssetUnsafe(addSoundExtIf(id), SOUND, useCache);
}
/**
- * Gets an instance of a sound, logs when the asset is not found
+ * Gets an instance of a sound, logs when the asset is not found.
+ *
+ * **Note:** If the `FLX_DEFAULT_SOUND_EXT` flag is enabled, you may omit the file extension
*
* @param id The ID or asset path for the sound
* @param useCache Whether to allow use of the asset cache (if one exists)
@@ -340,7 +360,7 @@ class AssetFrontEnd
*/
public inline function getSound(id:String, useCache = true, ?logStyle:LogStyle):Sound
{
- return cast getAsset(id, SOUND, useCache, logStyle);
+ return cast getAsset(addSoundExtIf(id), SOUND, useCache, logStyle);
}
/**
@@ -352,11 +372,25 @@ class AssetFrontEnd
* @return A new `Sound` object Note: Dos not return a `FlxSound`
*/
public inline function getSoundAddExt(id:String, useCache = true, ?logStyle:LogStyle):Sound
+ {
+ return getSound(addSoundExt(id), useCache, logStyle);
+ }
+
+ inline function addSoundExtIf(id:String)
+ {
+ #if FLX_DEFAULT_SOUND_EXT
+ return addSoundExt(id);
+ #else
+ return id;
+ #end
+ }
+
+ inline function addSoundExt(id:String)
{
if (!id.endsWith(".mp3") && !id.endsWith(".ogg") && !id.endsWith(".wav"))
- id += "." + #if flash "mp3" #else "ogg" #end;
+ return id + defaultSoundExtension;
- return getSound(id, useCache, logStyle);
+ return id;
}
/**
diff --git a/flixel/system/frontEnds/SoundFrontEnd.hx b/flixel/system/frontEnds/SoundFrontEnd.hx
index 3a40e9ddc5..4ecae68745 100644
--- a/flixel/system/frontEnds/SoundFrontEnd.hx
+++ b/flixel/system/frontEnds/SoundFrontEnd.hx
@@ -103,6 +103,8 @@ class SoundFrontEnd
/**
* Set up and play a looping background soundtrack.
*
+ * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension
+ *
* @param embeddedMusic The sound file you want to loop in the background.
* @param volume How loud the sound should be, from 0 to 1.
* @param looped Whether to loop this music.
@@ -132,6 +134,8 @@ class SoundFrontEnd
/**
* Creates a new FlxSound object.
*
+ * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension
+ *
* @param embeddedSound The embedded sound resource you want to play. To stream, use the optional URL parameter instead.
* @param volume How loud to play it (0 to 1).
* @param looped Whether to loop this sound.
@@ -230,6 +234,8 @@ class SoundFrontEnd
/**
* Plays a sound from an embedded sound. Tries to recycle a cached sound first.
*
+ * **Note:** If the `FLX_SOUND_ADD_EXT` flag is enabled, you may omit the file extension
+ *
* @param embeddedSound The embedded sound resource you want to play.
* @param volume How loud to play it (0 to 1).
* @param looped Whether to loop this sound.
diff --git a/flixel/system/macros/FlxDefines.hx b/flixel/system/macros/FlxDefines.hx
index c019da71ca..4bf4815839 100644
--- a/flixel/system/macros/FlxDefines.hx
+++ b/flixel/system/macros/FlxDefines.hx
@@ -52,6 +52,12 @@ private enum UserDefines
* any `` tags in your project.xml, to reduce your total memory
*/
FLX_CUSTOM_ASSETS_DIRECTORY;
+ /**
+ * Allows you to use sound paths with no extension, and the default sound type for that
+ * target will be used. If enabled it will use ogg on all targets except flash, which uses mp3.
+ * If this flag is set to any string, that is used for the file extension
+ */
+ FLX_DEFAULT_SOUND_EXT;
}
/**
@@ -100,6 +106,7 @@ private enum HelperDefines
FLX_STANDARD_ASSETS_DIRECTORY;
/** The normalized, absolute path of `FLX_CUSTOM_ASSETS_DIRECTORY`, used internally */
FLX_CUSTOM_ASSETS_DIRECTORY_ABS;
+ FLX_NO_DEFAULT_SOUND_EXT;
}
class FlxDefines
@@ -200,6 +207,7 @@ class FlxDefines
defineInversion(FLX_SWF_VERSION_TEST, FLX_NO_SWF_VERSION_TEST);
defineInversion(FLX_NO_HEALTH, FLX_HEALTH);
defineInversion(FLX_TRACK_POOLS, FLX_NO_TRACK_POOLS);
+ defineInversion(FLX_DEFAULT_SOUND_EXT, FLX_NO_DEFAULT_SOUND_EXT);
// defineInversion(FLX_TRACK_GRAPHICS, FLX_NO_TRACK_GRAPHICS); // special case
}
diff --git a/tests/coverage/Project.xml b/tests/coverage/Project.xml
index e53cc93d2e..46a00af3da 100644
--- a/tests/coverage/Project.xml
+++ b/tests/coverage/Project.xml
@@ -54,6 +54,7 @@
+