I get the sound cutting and disapearing randonly on all my games on HTML5. Also, on IE10, it sometimes reflects a AUDIO ERROR1! into the console, which I've been taking a look at, and it is caused by a InvalidStateError exception into gxtkSample.prototype.AllocAudio=function() of the native mojo js. that said, not sure where or why this AllocAudio is called, but if it is creaating the sound, it makes no sense to me, as the sound was created a lot earlier without issues. not sure what can be happening here.
While I'm debugging as much as I can, It seems channel zero is not playing any sound on HTML5 on Chrome. Also, on IE10, it seems it randmly creates the aforementioned exception and sound disappears.
This is my "mixer" class:
Global AudioMixer:Mixer
Class Mixer
Method New()
If running Then Error("Only one mixer allowed!")
running = True
End
'summary: el volumen general de la app
Method MainVolume:Void(value:Float) Property
If value > 1 Then value = 1
If value < 0 Then value = 0
mainVolume = value
RefreshVolume()
End
Method MainVolume:Float() Property
Return mainVolume
End
Method MusicVolume:Void(value:Float) Property
If value > 1 Then value = 1
If value < 0 Then value = 0
musicVolume = value
RefreshVolume()
End
Method MusicVolume:Float() Property
Return musicVolume
End
'summary: Disparar un sonido
'summary: Poner música en el canal de fondo
Method PlayMusic(path:String, flags = Mixer.MUSIC_LOOP)
audio.PlayMusic(path, flags)
End
Method StopMusic()
audio.StopMusic()
End
'summary: Gets or sets the global FxVolume
Method FxVolume:Void(value:Float) Property
If value > 1 Then value = 1
If value < 0 Then value = 0
fxVolume = value
RefreshVolume()
End
Method FxVolume:Float() Property
Return fxVolume
End
Method MusicFader:Void(value:Float) Property
musicFader = value
End
Method MusicFader:Float() Property
Return musicFader
End
'summary: Disparar un sonido
Method ShotSound(sound:Sound, volume:Float = 1, pitch:Float = 1)
If sound = Null Then Return
If ChannelState(currentChannel) <> 0 Then
StopChannel(currentChannel)
EndIf
Print "channel: " + currentChannel
PlaySound(sound, currentChannel)
SetChannelVolume(currentChannel, mainVolume * fxVolume * volume)
SetChannelRate(currentChannel, pitch)
soundVolume[currentChannel] = volume
currentChannel += 1
If currentChannel >= MAXCHANNELS Then currentChannel = 0
End
Method StopAllSounds()
For Local i:Int = 0 Until MAXCHANNELS
StopChannel(i)
Next
End
Const MUSIC_LOOP:Int = 1
Const MUSIC_ONCE:Int = 0
Private
Method RefreshVolume()
audio.SetMusicVolume(musicVolume * mainVolume * musicFader)
For Local i:Int = 0 Until MAXCHANNELS
audio.SetChannelVolume(i, mainVolume * soundVolume[i] * fxVolume)
Next
End
Field mainVolume:Float = 1
Field musicVolume:Float = 1
Field musicFader:Float = 1
Field currentChannel:Int = 1
Field fxVolume:Float = 1
Const MAXCHANNELS:Int = 10
Field soundVolume:Float[] = New Float[MAXCHANNELS]
Field running:Bool = False
End
|