[Solved] Disabled audio and InitSound()

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

[Solved] Disabled audio and InitSound()

Post by BarryG »

[Edit] SOLVED. See here -> viewtopic.php?p=640610#p640610

I've got all audio disabled on my PC but InitSound() doesn't return 0. I was hoping to use InitSound() so my app knows NOT to use audio APIs if it returns 0 for no audio, but I can't. :(

Code: Select all

Debug InitSound() ; 2253675236144

Image


Image
Last edited by BarryG on Sun May 11, 2025 9:56 pm, edited 2 times in total.
User avatar
jacdelad
Addict
Addict
Posts: 2009
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: 6.21 B9: Disabled audio and InitSound()

Post by jacdelad »

Doesn't InitSound() just build a bridge between you program and the Windows sound system (which itself looks for devices) and just returns that it "successfully connected to the Windows component"?
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
Fred
Administrator
Administrator
Posts: 18207
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 6.21 B9: Disabled audio and InitSound()

Post by Fred »

Nowaday the sound system will be almost always successful, because you can plugin USB headset etc. which can enable sound on the go. So you can't rely to InitSound() to detect a sound card
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Disabled audio and InitSound()

Post by Quin »

BarryG wrote: Sat May 10, 2025 5:49 am I've got all audio disabled on my PC but InitSound() doesn't return 0. I was hoping to use InitSound() so my app knows NOT to use audio APIs if it returns 0 for no audio, but I can't. :(
What do you mean, all audio disabled? You have all soundcards disconnected/disabled?
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: Disabled audio and InitSound()

Post by BarryG »

Hi Quin. Yes, what I mean is I went into Device Manager and disabled all audio components, because it turns out some users don't have sound cards, and my app was crashing for them due to it. So I need a way to detect if a sound card is present/enabled or not, and I thought InitSound() would do the job; but as Fred said, you can't use it like that. :(
AZJIO
Addict
Addict
Posts: 2187
Joined: Sun May 14, 2017 1:48 am

Re: Disabled audio and InitSound()

Post by AZJIO »

RunProgram() + "devcon status" ?

Code: Select all

EnableExplicit

If Not IsUserAnAdmin_()
	Debug "Admin?"
	End
EndIf

Define Compiler, Output$
Compiler = RunProgram("devcon", "status =media", "", #PB_Program_Open | #PB_Program_Read)
If Compiler
	While ProgramRunning(Compiler)
		If AvailableProgramOutput(Compiler)
			Output$ + ReadProgramString(Compiler) + Chr(13)
		EndIf
	Wend
	Output$ + Chr(13) + Chr(13)
	Output$ + "Exitcode: " + Str(ProgramExitCode(Compiler))

	CloseProgram(Compiler)
EndIf

MessageRequester("Output", "|" + Output$ + "|")
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

Re: [Solved] Disabled audio and InitSound()

Post by BarryG »

Sorry, forgot to say this was solved by mk-soft in another post (edited my first post here), without needing admin rights. Thanks for your post, too. :)
Post Reply