I want to play a sound file repeating during the entire game
Moderator: Moderators
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
I want to play a sound file repeating during the entire game
So can I just use playsoundstream in a widget to get it started, then use a timer to see if a set amount of time has passed to start it over and over again (looping)? And what would be the best way to deal with the timer?
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: I want to play a sound file repeating during the entire game
A little update, so I started it, because it seemed simple enough, however I hit some snags.
So I mean, it's simple enough. Looks for a sound and plays it. Ezpz. However, it directly interferes with my music player which is also using playsoundstream. However, in the wiki, I am led to believe that this shouldn't be an issue because "In 83.0 and up multiple sound streams may be played at once".
What am I doing wrong? Do I need to somehow differentiate this soundstream from all others?
Code: Select all
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: gui_ambientSoundPlayer.lua
-- brief: Plays a looping background sound
-- author: Forboding Angel
--
-- Copyright (C) 2019.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
math.randomseed( os.time() - os.clock() * 1000 )
math.random() math.random() math.random()
function widget:GetInfo()
return {
name = "Ambient Background Sound Player",
desc = "Plays a looping background sound",
author = "Forboding Angel",
date = "May 2019",
license = "GNU GPL, v2 or later",
layer = -4,
enabled = true -- loaded by default?
}
end
local ambientSoundFile = "luaui/sounds/ambient/ambient.ogg"
function widget:Initialize()
Spring.PlaySoundStream(ambientSoundFile)
Spring.SetSoundStreamVolume(1)
end
What am I doing wrong? Do I need to somehow differentiate this soundstream from all others?
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: I want to play a sound file repeating during the entire game
I've decided I need to use "Spring.PlaySoundFile Plays WAV or OGG sounds."
Except... the fuck it does. It refuses to play ogg files (complains that it can't find them). Good to know.
For reference...
https://i.imgur.com/bFfvYCr.png
Spring.PlaySoundFile("LuaUI/Sounds/ambient/ambient.ogg", 1.0, 'ui')
https://i.imgur.com/MtALgSu.png
Nope. Any reason that I shouldn't mantis this? The ogg is stereo, does that matter? Wav stereo plays just fine.
Except... the fuck it does. It refuses to play ogg files (complains that it can't find them). Good to know.
For reference...
https://i.imgur.com/bFfvYCr.png
Spring.PlaySoundFile("LuaUI/Sounds/ambient/ambient.ogg", 1.0, 'ui')
https://i.imgur.com/MtALgSu.png
Nope. Any reason that I shouldn't mantis this? The ogg is stereo, does that matter? Wav stereo plays just fine.
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: I want to play a sound file repeating during the entire game
For anyone that cares, the widget (all 2 relevant lines of it) is here:
https://github.com/EvolutionRTS/Evoluti ... Player.lua
It's a 60 second sound file (if I could use ogg it would be 30 minutes long, but for now wav seems to be the only thing that will work for playsoundfile). First 10 seconds are fade in and last 10 seconds are fade out. Starts playing on gameframe 1 and then repeats every 50 seconds (resulting in continuous background sound without volume difference due to overlapping fades).
I'm sure there are better ways to do the repeating, but I wanted something fairly simple so I figured this would do the trick.
Mantised the bug here:
https://springrts.com/mantis/view.php?id=6227
https://github.com/EvolutionRTS/Evoluti ... Player.lua
It's a 60 second sound file (if I could use ogg it would be 30 minutes long, but for now wav seems to be the only thing that will work for playsoundfile). First 10 seconds are fade in and last 10 seconds are fade out. Starts playing on gameframe 1 and then repeats every 50 seconds (resulting in continuous background sound without volume difference due to overlapping fades).
I'm sure there are better ways to do the repeating, but I wanted something fairly simple so I figured this would do the trick.
Mantised the bug here:
https://springrts.com/mantis/view.php?id=6227
Re: I want to play a sound file repeating during the entire game
Have you looked into how the music widget queues in diffrent files and blends them into one another?
Maybe just add a function that allows adding of other files to that widget?
Maybe just add a function that allows adding of other files to that widget?
- Forboding Angel
- Evolution RTS Developer
- Posts: 14673
- Joined: 17 Nov 2005, 02:43
Re: I want to play a sound file repeating during the entire game
Well I rewrote the music widget that we currently use as the original was so bad. Floris' and I fixed up the original, and then I rewrote it, and then Damgam added a ton of dynamic functionality to it.
In short, wouldn't have worked, additionally I am very adverse to locking in things to only work a single way. Keeping them separate was pretty important.
My little 2 liner works excellently so that basically solves that issue.
In short, wouldn't have worked, additionally I am very adverse to locking in things to only work a single way. Keeping them separate was pretty important.
My little 2 liner works excellently so that basically solves that issue.