No sound...
Monkey Forums/Monkey Beginners/No sound...
| ||
Hi all, This is a very simple problem but I just can't work out what's going wrong. I'm trying to play a wav sound in my GLFW game. This is a slightly simplified version of the code: <code> Global snd_click:Sound snd_click = LoadSound("audio/click.wav") If Not snd_click Print "Sound not loaded." End If PlaySound(snd_click, 1) </code> The "Sounded not loaded" message comes out every time and, unsurprisingly, no sound is heard. I've double-checked that my path is correct and - it is! The wav is a functional audio file. Any thoughts? Thanks, Ian |
| ||
hi Your code looks good. Are you really sure of your file location ? What section do you use ? What the size of your wav file ? |
| ||
What's the directory structure? See what Strict Import mojo Class CGame Extends App Field audio:Sound Field loopCount:Int Field playedCount:Int Method OnCreate:Int() audio = LoadSound("audio/shoot.wav") If Not audio Then Print "Sound not Loaded" Else Print "Playing in OnCreate"; PlaySound(audio,1) Return 0 End Method OnUpdate:Int() If Not ChannelState(1) Then playedCount += 1; PlaySound(audio,1) 'PlaySound(audio,1) 'Uncomment this to break playing of sound loopCount += 1; Return 0 End Method OnRender:Int() DrawText("Played Count:" + playedCount,0,0) DrawText("Loop Count " + loopCount,0,20) Return 0 End End Function Main:Int() New CGame Return 0 Enddoes. You should check that a channel has finished playing before reusing it. Note: This code expects a directory called audio in the myapp.data directory. And try using a different audio file like the ones that Mark has supplied in the examples. |
| ||
Thanks for the replies. My data folder contains a sub-folder called audio and the wav file is in that. I've tried moving the wav file up a level (and changed the file reference accordingly) but still no good. It seems like the sound just won't load. Maybe I'll try a different file. |