Page 1 of 1

How to include and play wav/ogg within exe?

Posted: Tue Feb 21, 2023 3:49 am
by mkes84
Hi,

Apologies if this is a dumb question but I've been trying to include a small ogg file in my binary and play it when the application starts. The problem is, I keep getting the error on the PlaySound() command:

"The specified #Sound is not initialised."

Code: Select all

.
.
.
InitSound()
UseOGGSoundDecoder()

OpenwinMain() ; Open the first window. This procedure name is always 'Open' followed by the window name

CatchSound(0, ?Music)
PlaySound(0) ; Error: "The specified #Sound is not initialised."

Repeat
  Event = WaitWindowEvent()
  
  Select EventWindow()
    Case MainWindow
      winMain_Events(Event) ; This procedure name is always window name followed by '_Events'
  EndSelect  
Until Event = #PB_Event_CloseWindow ; Quit on any window close

DataSection
  Music:
    IncludeBinary "song.ogg"
EndDataSection
Can anyone please help?

Thank you!

Re: How to include and play wav/ogg within exe?

Posted: Tue Feb 21, 2023 3:56 am
by jacdelad
Your code is not executable, please post a minimal, executable code next time.

However, I can't find an error in your code (the part for playing the ogg file). Have you tried using a different file, like a *.wav (just for testing)? What does CatchSound() return?

Another shot into the dark: include the length of the sound when catching it.

Re: How to include and play wav/ogg within exe?

Posted: Tue Feb 21, 2023 5:21 am
by RASHAD
Hi
This is your first post and your aka ends with 84 I hope you are not a spam :wink:
You must include the file Size in CatchSound() if you are using Ogg or Flac
The doc must be corrected

Code: Select all

InitSound()

UseOGGSoundDecoder()

OpenWindow(0,0,-300,0,0,"")

 CatchSound(0, ?Music,?Musicend-?Music)

PlaySound(0) ; Error: "The specified #Sound is not initialised."

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow

  EndSelect  
Until Quit = 1

DataSection
  Music:
    IncludeBinary "g:\mmedia\sounds\01AlicesRestaurantMassacree.ogg"
  Musicend:
EndDataSection

Re: How to include and play wav/ogg within exe?

Posted: Tue Feb 21, 2023 11:51 pm
by mkes84
Thank you! Thank you! It worked. I really appreciate both of your help.