Sound.hx:118: Error: Could not load "assets/music/mysound.ogg"

Disclaimer: This issue persists with HaxeFlixel projects. It was suggested that the cause may lie within OpenFL. I have opened an issue on the OpenFL GitHub repository.

The Problem: Every odd start of the game, it doesn’t have any sound. This has been happening across projects.

I’ve prepared a completely clean template project, with the Main.hx looking like this:

package;

import flixel.FlxGame;
import openfl.display.Sprite;

class Main extends Sprite
{
	
	public function new()
	{
		super();
		addChild(new FlxGame(256, 192, TitleScreen, 1, 60, 60, true));
	}
}

And the TitleScreen.hx looking like this:

package;

import flixel.FlxG;
import flixel.FlxState;

class TitleScreen extends FlxState
{
	override public function create():Void
	{
		#if flash
		FlxG.sound.playMusic("assets/music/mysound.mp3");
		#else
		FlxG.sound.playMusic("assets/music/mysound.ogg");
		#end
		
		super.create();
	}

	override public function update(elapsed:Float):Void
	{
		super.update(elapsed);
	}
}

The Project.xml is unchanged and the only two assets are the two mp3/ogg files.

While the windows target runs the game without sound, the neko target crashes whenever the issue occurs, tracing this:

Build succeeded
Done(0)
haxelib run lime run "Project.xml" neko -debug
Running process: D:\Pizza\Development\HaxeToolkit\haxe\haxelib.exe run lime run "Project.xml" neko -debug
Sound.hx:118: Error: Could not load "assets/music/mysound.ogg"
AL lib: (EE) MMDevApiOpenPlayback: Device init failed: 0x80004005
Invalid operation (/)
Called from flixel.system.FlxSound::update line 241
Called from flixel.system.frontEnds.SoundFrontEnd::update line 273
Called from flixel.FlxGame::update line 696
Called from flixel.FlxGame::step line 648
Called from flixel.FlxGame::onEnterFrame line 493
Called from openfl._legacy.events.EventDispatcher::dispatchEvent line 98
Called from openfl._legacy.display.DisplayObject::__dispatchEvent line 182
Called from openfl._legacy.display.DisplayObject::__broadcast line 161
Called from openfl._legacy.display.DisplayObjectContainer::__broadcast line 280
Called from openfl._legacy.display.Stage::__render line 1103
Called from openfl._legacy.display.Stage::__checkRender line 351
Called from openfl._legacy.display.Stage::__pollTimers line 1084
Called from openfl._legacy.display.Stage::__doProcessStageEvent line 430
Done(1)

Clues:
The problem does occur on the windows target, resulting in no sound.
The problem does occur on the neko target, resulting in a crash.
The problem does not occur on the flash target.
The problem does not occur when running the game in fullscreen mode (with FlxG.fullscreen = true;).
The problem does not occur when disabling windows visual designs (aero).

.zip of the project:


.zip of the windows cpp bin directory:

Thank you very much in advance.

Does this occur with the “PlayingSound” or “PiratePig” samples? Thanks!

Yes, using theme.ogg from PiratePig, the same issue occured. No sound on the fourth run of the application.

Thank you for taking a look at the issue.

Might this be related?

https://steamcommunity.com/app/253790/discussions/0/540732347262423880/

We might have a fix, definitely an explanation:

https://github.com/openfl/openfl/issues/998#issuecomment-170916553

You’re using HaxeFlixel, it uses OpenFL legacy by default. Do you know if this is what you are using? If so, an issue like grapefrukt mentioned would not have changed. Does it behave differently with the current OpenFL? (using -Dnext in Flixel)

I’m using HaxeFlixel with OpenFL legacy. -Dnext crashes immediately.

I’ve been getting it to run by downgrading to Lime 2.8.2. The issue doesn’t seem to be persistent here. The project seems to start delayed in just the way that grapefrukt’s fix would have worked. Does OpenFL next have this fix already included perhaps?

We don’t use a workaround like he does, but we have a totally different way of managing OpenAL and audio, which might be better and more mature

It seems like neither this issue, nor the one where the sound would cut out after so-and-so much plays is persistent with OpenFL next. I wouldn’t mind using it generally. Is there anything I’d have to be aware of? Any way to default to it for compilation? I’d also close the issues on github after some further testing with a note that the issues aren’t persistent with OpenFL next. Would that be okay?

Certainly :slightly_smiling:

Flixel uses -Dlegacy by default, but we don’t. Standard OpenFL uses the current code. If you use Flixel, they added a “-Dnext” define to prevent it from forcing legacy.

I heard about a crash on release builds with Flixel with the current release, due to an asset the splash screen uses. I think disabling the splash screen or doing a -Ddebug build works with the latest, but we’re still investigating a permanent fix

So in legacy mode there is no ogg support?