How to include and play wav/ogg within exe?

Just starting out? Need help? Post your questions and find answers here.
mkes84
New User
New User
Posts: 2
Joined: Tue Feb 21, 2023 3:41 am

How to include and play wav/ogg within exe?

Post 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!
User avatar
jacdelad
Addict
Addict
Posts: 2046
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

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

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5014
Joined: Sun Apr 12, 2009 6:27 am

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

Post 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
Egypt my love
mkes84
New User
New User
Posts: 2
Joined: Tue Feb 21, 2023 3:41 am

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

Post by mkes84 »

Thank you! Thank you! It worked. I really appreciate both of your help.
Post Reply