[Solved] Game plays sound once and then cannot find file
-
I'm trying to extend the Breakout Demo in order to learn my way around HaxeFlixel, and I'm struggling with getting a sound to play every time the ball hits a block.
I call up the sound inside the hit function with the line
FlxG.sound.play(AssetPaths.hit__wav);
This plays the first time a block is hit but immediately throws an error:[ERROR] Could not find a Sound asset with an ID of 'assets/sounds/hit.wav'.
After this first hit, the sound never plays again. If I play again without restarting the entire application, the game crashes when the ball hits a first block again with the following error:
Called from sys.io.FileOutput::$statics line 1
Called from ApplicationMain::main line 84
Called from ApplicationMain::create line 116
Called from lime.app.Application::exec line 269
Called from lime._backend.native.NativeApplication::exec line 160
Called from a C function
Called from lime._backend.native.NativeApplication::handleRenderEvent line 453
Called from lime.app._Event_Void_Void::dispatch line 101
Called from openfl.display.Stage::addRenderer line 332
Called from openfl.display.Stage::render line 942
Called from openfl.display.Stage::__broadcastEvent line 1032
Called from openfl.display.Stage::__handleError line 1308
Called from openfl.display.Stage::__broadcastEvent line 1028
Called from openfl.display.DisplayObject::__dispatch line 453
Called from a C function
Called from openfl.events.EventDispatcher::__dispatchEvent line 217
Called from flixel.FlxGame::onEnterFrame line 538
Called from flixel.FlxGame::step line 665
Called from flixel.FlxGame::update line 735
Called from flixel.FlxState::tryUpdate line 172
Called from PlayState::update line 185
Called from flixel.FlxG::overlap line 397
Called from flixel.system.FlxQuadTree::execute line 593
Called from flixel.system.FlxQuadTree::execute line 593
Called from flixel.system.FlxQuadTree::execute line 601
Called from flixel.system.FlxQuadTree::execute line 584
Called from flixel.system.FlxQuadTree::overlapNode line 660
Called from PlayState::hit line 191
Called from a C function
Called from flixel.system.frontEnds.SoundFrontEnd::play line 194
Called from flixel.system.FlxSound::set_volume line 690
Called from flixel.system.FlxSound::updateTransform line 547
Uncaught exception - Invalid field access : volumeI've ensured that my AssetPaths are defined in
AssetPaths.hx
inside my source folder as such:package; @:build(flixel.system.FlxAssets.buildFileReferences("assets", true)) class AssetPaths {}
Anecdotally, my IDE also autocompletes the path to the hit sound when using AssetPaths, so every appears to be set up correctly.
I also just tested building outside of my IDE (vscode) with the command
lime test linux -64 -debug
and got the following crash when I tried to play the game a second time in a row, as above:Called from openfl.display.DisplayObject::__dispatch openfl/display/DisplayObject.hx line 453
Called from openfl.events.EventDispatcher::__dispatchEvent openfl/events/EventDispatcher.hx line 217
Called from flixel.FlxGame::onEnterFrame flixel/FlxGame.hx line 538
Called from flixel.FlxGame::step flixel/FlxGame.hx line 665
Called from flixel.FlxGame::update flixel/FlxGame.hx line 735
Called from flixel.FlxState::tryUpdate flixel/FlxState.hx line 172
Called from PlayState::update PlayState.hx line 185
Called from flixel.FlxG::overlap flixel/FlxG.hx line 397
Called from flixel.system.FlxQuadTree::execute flixel/system/FlxQuadTree.hx line 593
Called from flixel.system.FlxQuadTree::execute flixel/system/FlxQuadTree.hx line 593
Called from flixel.system.FlxQuadTree::execute flixel/system/FlxQuadTree.hx line 601
Called from flixel.system.FlxQuadTree::execute flixel/system/FlxQuadTree.hx line 583
Called from flixel.system.FlxQuadTree::overlapNode flixel/system/FlxQuadTree.hx line 660
Called from PlayState::hit PlayState.hx line 191
Called from flixel.system.frontEnds.SoundFrontEnd::play flixel/system/frontEnds/SoundFrontEnd.hx line 194
Called from flixel.system.FlxSound::set_volume flixel/system/FlxSound.hx line 690
Called from flixel.system.FlxSound::updateTransform flixel/system/FlxSound.hx line 543
Error : Null Object ReferenceAny help resolving this issue would be appreciated. Please let me know if you would like more information of any sort.
-
odd. I tried to duplicate the problem and when I use an ogg file it works fine (neko and windows), but with a copy of a wav file that I've already used in another project, it crashed. So I opened it up in Audacity and exported as
32 bit Float PCM
wav and it didn't crash but made no sound. I then exported it as16 bit PCM
and it worked. The original was 16 bit PCM, so I'm not sure why it didn't work. Something to do with making a copy? Anyway, it looks like wav 16 bit PCM works, but only after I exported it as a new file. The copy/paste file didn't work. Maybe someone knows why this is?tldr: Open the file in Audacity and export it as a new wav file with 16 bit PCM
EDIT:
I didn't notice you were using linux. But I did have a similar problem with windows build. Not sure it will help with your problem.
-
i had a similar error with a sound file that embeds data. try removing all data from the sound file such as the year it was made or the name of the sound file in audacity. that should stop the sound crash.
EDIT: also, as I was programming, I documented all the strange happenings such as music crash or making tiled maps, bugs, etc. you might find useful this file https://github.com/galoyo/SpaceCastle/blob/master/dev/README FIRST.html
-
(First of all, as a side note: I'm an idiot that didn't realize the "my sound playing one time" was actually the bleep the debugger makes when it throws up an error...woops.)
I looked at your README, @galoyo, and that actually completely solved my problem. I hadn't found mention about setting the asset paths in the
Project.xml
until now and yours was quite enlightening, and actually makes sense why my sound wasn't playing and the error it was throwing in the debugger!To be more explicit for the sake of including everything here for posterity, I had to define my sounds in
Project.xml
like so:<assets path="assets" if="flash" exclude="*.ogg" /> <assets path="assets" if="windows" exclude="*.mp3" embed="true" /> <assets path="assets" if="neko" exclude="*.mp3" embed="true" /> <assets path="assets" if="linux" exclude="*.mp3" embed="true" /> <assets path="assets" if="html5" exclude="*.mp3" embed="true" /> <assets path="assets/sounds" rename="sounds" if="flash" embed="true"> <sound path="mySound.mp3" id="mySound" /> <sound path="myOtherSound.mp3" id="mySound2" /> </assets> <assets path="assets/sounds" rename="sounds" unless="flash" embed="true"> <sound path="mySound.ogg" id="mySound" /> <sound path="myOtherSound.ogg" id="myOtherSound" /> </assets>
Then, I called the sounds in my code like so:
FlxG.sound.play("mySound", 1, false); FlxG.sound.play("myOtherSound", 1, false);
And that's all there is to it! Since I'm on Linux, I could simply use ffmpeg to convert my original sound files, such as wav files, to the appropriate mp3 and ogg formats like so:
ffmpeg -i mySound.wav mySound.mp3 ffmpeg -i mySound.wav mySound.ogg
Thanks again to both of you for helping me!