This should work. Most likely, the sound is not found, maybe you
expect
the relative URL to be resolved against another base URL than it is
actually resolved. The relative URL is set as the "src" of a generated
HTML5 <audio> element, so it has to be relative to the URL of the
surrounding HTML page.
Also make sure that the browser can play mp3s, and that the server
uses the correct content type.
You could try a static HTML5 test page using <audio src="sound/..."/>
and see if that works. If it doesn't, you have another, more basic
problem
that does not have to do with Jangaroo at all.
If all this does not work, there is an alternative way, the way Flixel
does it,
which I made work with Jangaroo, which is to embed the sound, like so:
package foo.bar {
public class Player {
[Embed(source="../../data/hit.mp3")]
protected var SndHit:Class;
public function createAndPlay():void {
var sound:Sound = new SndHit();
sound.play();
}
}
}
Note the relative path: the two ../ are to navigate from "foo.bar"
back to the root package, where we have a top-level folder
"data" holding the sound files. So the example sound file should be
placed in src/main/joo/data/hit.mp3 (for build process / deployment,
see below).
Because some browsers (Firefox?) do not play mp3s, Jangaroo
tries to load an ogg sound from the same base URL as a fallback.
You can use some tool like Audacity to produce oggs from your
mp3s.
When building via Maven, you have to tell Maven in your pom.xml
to deploy the sound resources to the correct location in the Web-app,
in case of [Embed] this is the sub-path joo/classes:
<resources>
<resource>
<directory>src/main/joo</directory>
<includes>
<include>**/*.png</include>
<include>**/*.mp3</include>
<include>**/*.ogg</include>
<include>**/*.ttf</include>
<include>**/*.txt</include>
</includes>
<targetPath>joo/classes/</targetPath>
</resource>
</resources>
Find a fully-working example at
https://github.com/fwienber/Mode
Note that there, sounds are played through the helper class
FlxSound (which you'd find in
https://github.com/fwienber/flixel),
but it basically delegates to flash.media.Sound. So the tricky
part is where to put the sound files and how the annotated
field has to look like.
Good luck!