Search code examples
androidc++audiohaxeopenfl

openfl - audio doesn't work on cpp target


I've added <assets path="assets/audio" rename="audio" /> to the application.xml file.

And I load the "mp3" files in the audio folder by calling Assets.getSound("2_3_1.mp3");, and then use the .play(); method on that (sound) object to play the file.

The sounds play in flash target. But don't play on cpp targets. I'm mainly targeting Android (cpp) and iOS (c#) targets for my app.

When debugging for windows (cpp) target, it shows these errors in console:

Sound.hx:99: Error: Could not load "audio/2_3_1.mp3"
Error opening sound file, unsupported type.
Error opening sound data
Done(0)

Solution

  • I believe mp3 isn't supported on Windows and most other targets due a decision related to licensing costs for the format.

    The Flash target is an exception since Adobe has an agreement that allows developers to use the format without paying royalties. This is discussed more here: http://www.openfl.org/blog/2013/09/18/to-mp3-or-not-to-mp3/

    A workaround is to use the .ogg format for non-Flash platforms for audio, and include the audio files for each platform by specifying the asset paths in your Project.xml e.g:

    <assets path="assets/music" type="music" if="flash"> <!-- mp3s --> </assets> <assets path="assets/music" type="music" unless="flash"> <!-- oggs --> </assets>