Greetings everyone.
I have music files in a folder and I want them to constantly play at background, so, when one ends, another one starts playing. Unfortunately, I don't see any possibility in Love2d to detect the end of sound file. Is it even possible?
A question about music
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: A question about music
If it's not looped, it stops playing at the end. As in, the playsate changes to "stopped". You can detect this and play the next track.
Re: A question about music
Well I created this code and it does not seem to work properly.
Music starts at the beginning of the game but as soon as it ends, nothing happens.
Code: Select all
----
local music_volume = 0.5
--local sound_volume = 1
----
music = love.audio.newSource("music/mus_"..math.random(11)..".mp3", "stream" )
----
if music:isPlaying( ) == false then
math.randomseed( os.time() )
math.random(); math.random(); math.random(); math.random(); math.random()
music = love.audio.newSource("music/mus_"..math.random(11)..".mp3", "stream" )
love.audio.play( music )
music:setVolume(music_volume)
end
Re: A question about music
Simply put
into love.update()
Code: Select all
if music:isPlaying( ) == false then
math.randomseed( os.time() )
math.random(); math.random(); math.random(); math.random(); math.random()
music = love.audio.newSource("music/mus_"..math.random(11)..".mp3", "stream" )
love.audio.play( music )
music:setVolume(music_volume)
end
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: A question about music
Example:
Code: Select all
music = love.audio.newSource("music/mus_"..math.random(11)..".mp3", "stream" )
music:setLooping(true)
-- Then call music:play() somewhere in your code that's not the update function.
Edit: I seem to have misread the actual issue; this only loops one track. I will give an edited version of
Code: Select all
if not music:isPlaying( ) then
music = love.audio.newSource("music/mus_"..love.math.random(11)..".mp3", "stream" )
-- ^ or love.math.random(1,11) if you lack a mus_0.mp3
music:setVolume(music_volume)
love.audio.play( music )
end
Last edited by zorg on Wed Jun 19, 2019 10:38 pm, edited 1 time in total.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: A question about music
I put the code into love_update() and nothing is playing now. This neither works when I have it in a separate .lua file nor in main.lua.
Re: A question about music
lmaoKeisser wrote: ↑Wed Jun 19, 2019 5:02 pmCode: Select all
math.randomseed( os.time() ) math.random(); math.random(); math.random(); math.random(); math.random()
This would be the perfect time to post the exact code that shows the issue that can be run with a minimum amount of effort for anyone else trying to reproduce it.I put the code into love_update() and nothing is playing now. This neither works when I have it in a separate .lua file nor in main.lua.
Re: A question about music
Yeesh, that guy's a grump allright.
The proper spelling is "love.update". The "update" function is in the table "love". Make sure you never define another "love.update" function, it'll overwrite the last one.
The proper spelling is "love.update". The "update" function is in the table "love". Make sure you never define another "love.update" function, it'll overwrite the last one.
Re: A question about music
Wut? Nah. A grumpy response would have been a link to How To Ask Questions The Smart Way without further comment. Also, please don't assume my gender.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 1 guest