Sound working for anyone using MacOSX and Safari?

Monkey Targets Forums/HTML5/Sound working for anyone using MacOSX and Safari?

Waldo Reed(Posted 2012) [#1]
Reading this forum from a year ago sound was broken in HTML5. Running cometCrusher from Monkey Game Development - Beginners Guide I get sound when building the project in Flash but not in HTML5.

Looking at the projects Flash and HTML5 build directories, I see only mp3 files in the data directory under Flash but mp3, ogg, and wav files in the data directory under HTML5. I'll specify the file extension for each type and maybe get lucky.

-------------------------------------------
UPDATE - I got lucky and answered my own question; Yes sound is working in HTML5 on MacOSX and Safari.

The book code for cometCrusher used the file name for each sound. While it worked for the Flash build, no sound was heard for the HTML5 build. Changing "file name" to "file name.file extension" in the code got me sound with the HTML5 build. Here's my results...

eng.LoadSound("Explosion") 'sound in Flash build but no sound in HTML5 build
eng.LoadSound("Explosion.ogg") 'no sound in either Flash or HTML5
eng.LoadSound("Explosion.wav") 'no sound in Flash, but sound in HTML5
eng.LoadSound("Explosion.mp3") 'sound in both Flash and HTML5

So if I were to release in both Flash and HTML5, the simplest sound type to use is mp3.


Jesse(Posted 2012) [#2]
check out the audio format and browser support:
http://www.w3schools.com/html/html5_audio.asp


Waldo Reed(Posted 2012) [#3]
If we don't specify the extension as in the following line of code

eng.LoadSound("Explosion")

then what is supposed to determine which sound file format is played?

Does the translator have a certain order it looks for sound formats. And .ogg is listed ahead of the others so that's why I got no sound on MacOSX and Safari?


Difference(Posted 2012) [#4]
eng.LoadSound("Explosion")


You have to supply the full name of your file, *with extension*.

Look at the /bananas/mak/audiotest.monkey -> Method OnCreate() to see one way of selecting the format based on target.

HTML5 is a pain, because not all browseres support the same formats. (see Jesse's link)


MikeHart(Posted 2012) [#5]
Waldo,

fantomEngine added the file extension in its early versions based on the platform. These days you can add the file extension and it will load that. You will hear something if the platform supports it then.

Here is are the platform and extension, fantomEngine adds automatically when you don't provide a file extension:

[monkeycode]
#If TARGET="glfw"
snd.sound = mojo.LoadSound(fn+".wav")
#Elseif TARGET="html5"
snd.sound = mojo.LoadSound(fn+".ogg")
#Elseif TARGET="flash"
snd.sound = mojo.LoadSound(fn+".mp3")
#Elseif TARGET="android"
snd.sound = mojo.LoadSound(fn+".ogg")
#Elseif TARGET="xna"
snd.sound = mojo.LoadSound(fn+".wav")
#Elseif TARGET="ios"
snd.sound = mojo.LoadSound(fn+".m4a")
#End

[/monkeycode]


Jesse(Posted 2012) [#6]
#Elseif TARGET="html5"
                        snd.sound = mojo.LoadSound(fn+".ogg")


that doesn't work for safari.

I think you need to do something like what Diddy is doing to determine which file type to use depending on browser.



.


Waldo Reed(Posted 2012) [#7]
Jesse beat me to it but thanks Mike, you've confirmed the ogg version is used as deafult by the fantomEngine and thus why I'm not getting a sound in Safari.

And thanks Difference, I was planning on going through the Monkey samples after finishing Monkey Game Development - Beginners Guide.


MikeHart(Posted 2012) [#8]
thanks Jesse, i did not know that you can determine, which browser you are running on.