Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Play wav file in the background without a window on the forground
#1
Hello,
I did a lot of tests to play a wav file, and they all work, (mostly examples via the F1 help function).
But I want to play a wav file in the background without the classic (black) window on the foreground.

I do not found it  Sad

Somebody an idea what I need to do?

Rudy M
Reply
#2
I don't understand what you want exactly.   Do you want to play a WAV from a console only application ?

Or is it the CONSOLE window you want to hide !

https://qb64phoenix.com/qb64wiki/index.php/SCREENHIDE

https://qb64phoenix.com/qb64wiki/index.php/CONSOLE

https://qb64phoenix.com/qb64wiki/index.php/$CONSOLE
Reply
#3
Something like this:

Code: (Select All)
_ScreenHide
handle = _SndOpen("foo.wav")
_SndPlay handle
Do While _SndPlaying(handle)
_Delay .1
Loop
System
Reply
#4
If you want the sound, but no screen, Steve showed you an example, but I'll include this routine...

Code: (Select All)
_ScreenHide
dir$ = "C:\tmp-copy-qb64bas\" ' Change to your directory.
file$ = "test1.wav" ' Download the attached wav file to your directory.
h& = _SndOpen(dir$ + file$)
If h& Then _SndPlay h&
_Delay 15 ' Needs to be as long or longer than the wav duration, or use Steve's loop delay.
System

Oh, the voice in the test wav file is not mine. Spriggsy, maybe?

Pete


Attached Files
.wav   test1.wav (Size: 76.05 KB / Downloads: 21)
Reply
#5
Thank you all for sharing your experience/knowledge.

I had already tested all the "examples" (using the F1 key), but I always got a separate window. 
It's not that I'm too lazy to search myself! I'm blind in my right eye, which I can't see anything through, but... it's light-sensitive and starts to hurt after searching the screen for too long. (Which was the case yesterday, hence my question on the forum). 

I tested the routines from Neil and Pete, and they both work perfect on my Linux PC
@Pete: Indeed, I use a separate map to store all my sound and messages for my beer brewing software.
So its a good Idee to use a separate path and name variable, thanks!

@ahenry: The goal is to display spoken prompts in my brewing software
A simple but typical example: 
During the beer-boiling proces (approximately 1 hour), you can add hops at different times. 
If you add hops at the beginning, you get the bitter flavors. 
If you add hops 5 or 10 minutes before the end, for example, you get the aromatic compounds of certain hop varieties in your beer. (Example: Citra hops literally add "citrus"-like aromas to the beer.) 

Back to QB64: 
During the boiling process, I'll display a message on the screen at the set time, but simultaneously play the corresponding sound file. 
For example: "Now add the Citra hops," and repeat this until the user presses the spacebar (or another key). I've already tested the two examples from Neil and Pete, and they work perfectly, thanks for that. 
I'll definitely try out Ahenry's links today. 

Also a possible tip for the Raspberry Pi (I use Model 4B with 4 or 8GB of RAM): 
Because it was impossible to get QB64PE working, I installed the old QB64 version, and it works perfectly (so far),
both under Linux 64-bit (I always Install via the RaspberryPI Imager because this gives good working environments). 
I've already tested a few simple timer routines there, and they work identically on both versions (it's not always easy, though...). 
So now I can program on my regular PC with a large screen and then transfer it to the Raspberry Pi. 
Sorry for the long reply, but I wanted to clarify. Just so you don't think "I'm a lazy programmer."

Thanks!
Rudy M

Code: (Select All)

'Partly me Freebasic routine who is present in a big cookingroutine
'(Translated from Dutch to Englisch via Google Translate)

'Should hops be added?
'All hops are present in an array
'Variables are partly globas, partly declared in the cookingroutine

FOR Hop = 1 TO 8
  IF AddHop(Hop) = true THEN
    HopCookTimeSec = (HopCookTime(Hop) * 60) 'min. to sec'
    IF RemainingSeconds <= HopCookTimeSec THEN
      PlayMusic("AddHopsAndHerbs.wav")
      print
      Print " Add to brew kettle: "; HopName(Hop)
      Print " Weight: "; HopWeight(Hop); "kg"
      print " Note: weight is expressed in kg (0.005 kg = 5 grams!)" 'See remark (*)
      print " Press any key to continue."
      Key = getkey
      AddHop(Hop) = false
      cls
      PrintCookData
    end if
  end if
next Hop
print

'(*)
'For weights and volumes I use alwas the format "yyy.xxx"
'where yyy is the kg or liter part and xxx the gram of milli-literpart
'so an amateurbrewer (pe 50 liter beer),
' but also a microbrewer (pe 600 liter beer) can use the listing
Reply
#6
Glad you got it up and brewing, and thanks for giving a shout out to my partner in crime, Neil. He needs the encouragement!

Pete  Big Grin
Reply
#7
Dear programmers,

After testing all the tips from forum members ahenry3068, SMcNeill, and Pete, I realized I was doing it wrong.
Hiding a screen, playing music in the background, and still publishing information in a window is already ridiculous. 
That's why I started experimenting with the QB64PE examples (using F1 and clicking on keywords...).
I changed the font example to a large font (for my eyes...), but anyone who wants to use this can, of course, use a smaller font.

Now I need to experiment a bit with QB64's "play" capabilities to display my spoken information in the background. Either with the QB64 keywords or possibly using a separate C++ library.

Rudy M
Code: (Select All)

'Original source: https://qb64.com/wiki/_FONT.html

'Windows:
'Change to Your Windows Folder Path.
'fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf"

'Linux:
'Change to Your Linux font path
'For me: (on my Lenovo Linux Mint PC) /usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf

fontpath$ = ENVIRON$("SYSTEMROOT") + "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf"

DO: CLS

  style$ = "MONOSPACE"

  'I have an eye problem, so I need a big font:
  fontsize% = 26 'Need to be between 7 and 26)

  '(0) for REGULAR OR (1) for ITALIC FONT
  italic% = 0

  '(0) for REGULAR OR (1) for BOLD FONT: ", bold%
  bold% = 0
  IF italic% = 1 THEN style$ = style$ + ", ITALIC" ELSE style$ = style$ + ", REGULAR"
  IF bold% = 1 THEN style$ = style$ + ", BOLD" ELSE style$ = style$ + ", NORMAL"

  GOSUB ClearFont
  font& = _LOADFONT(fontpath$, fontsize%, style$)
  _FONT font&

  PRINT
  PRINT "This is the font of Your choice"
  PRINT style$
  PRINT fontsize%
  PRINT italic%
  PRINT bold%: PRINT: PRINT
  PRINT "12345678901234567890123456789012345678901234567890123456789012345678901234567890abcdefghij"
  PRINT: PRINT "You have 80 characters to display on each screenline"
  PRINT "More then 80 characters in the txtline are going to the next line.";

  DO: SLEEP: K$ = UCASE$(INKEY$): LOOP UNTIL K$ = CHR$(27) OR K$ = CHR$(13)

LOOP UNTIL K$ = CHR$(27) OR K$ = CHR$(13)

GOSUB ClearFont

PRINT "This is the QB64 default _FONT 16!"
END

ClearFont:
IF font& > 0 THEN
  _FONT 16 'select inbuilt 8x16 default font
  _FREEFONT font&
END IF
RETURN
Reply
#8
For use in my programs, I simplify it as:

Code: (Select All)
myfont& = _LoadFont(Environ$("SYSTEMROOT") + "\fonts\lucon.ttf", 26, "MONOSPACE")
_Font myfont&
Print "Hello World!"
Sleep ' Enlarge font demo over. Now restore the original font and screen size.
_Font 16
If myfont& Then _FreeFont myfont&

Pete
Reply
#9
Hey Pete, how does line 6 work in the above example? That checks for a valid handle before _Freeing the font? Do tell…
Reply
#10
(09-18-2025, 02:28 PM)NakedApe Wrote: Hey Pete, how does line 6 work in the above example? That checks for a valid handle before _Freeing the font? Do tell…

It does.  A valid font hand is going to be a value greater than 0, so if a font fails to load, that handle is going to be 0.
That IF statement holds true -- but only in this limited case -- because if the font fails to load, the handle would be 0 and then it'd skip that call to _FREEFONT.

My suggestion for more verstile usage?

Code: (Select All)

myfont& = _LoadFont(Environ$("SYSTEMROOT") + "\fonts\lucon.ttf", 26, "MONOSPACE")
_Font myfont&
Print "Hello World!"
Sleep ' Enlarge font demo over. Now restore the original font and screen size.
_Font 16
If myfont& Then 
   _FreeFont myfont&
   myfont& = 0
End If

Make certain to reset that handle to 0 after you free it.  Otherwise, if you call that same line a second time (such as in a loop), myfont& is still going to be non-zero, but the font has already been freed and you'd generate an error.

This works here, as it is, because it's not called in a loop, and only called once.  If you were to call it twice, the second call would error out as you've already freed the font.  The handle doesn't change unless you change it yourself.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Enlarging window for older BAS programs (ie. Screen 7 mode) paulel 5 413 12-24-2025, 09:36 PM
Last Post: paulel
Music export _memsound buffer into wav file hsiangch_ong 2 314 12-12-2025, 10:28 PM
Last Post: hsiangch_ong
  auto-detecting screen resolution for optimal window size on non-Windows systems madscijr 11 1,080 11-10-2025, 07:23 PM
Last Post: madscijr
  is there any way to position the inputbox$ window? madscijr 21 1,686 11-06-2025, 09:54 PM
Last Post: madscijr
  auto-detecting screen resolution for optimal window size on non-Windows systems madscijr 0 226 10-26-2025, 06:58 PM
Last Post: madscijr

Forum Jump:


Users browsing this thread: 1 Guest(s)