Hi, I'm have a stab at löve-making and was wondering how to display the current time (elapsed) from an audio file via a key press call. Here is my attempt (I'm not even sure if tried to call the right function here) -- The error is about using a nil value so I guess I'm not calling the value correctly.
function love.keypressed(key)
if key == "f1" then
x, y, z = love.audio.getPosition()
text = text .. string.x
text = text .. string.y
text = text .. string.z
love.audio.pause(audioSource)
status = "PAUSED"
end
if key == "f2" then
love.audio.resume(audioSource)
-- NOTE TO FUTURE SELF:
-- Put resume / pause in array. Call array index, then index
-- switch so if key is pressed again, result is different.
status = "RESUMED"
end
if key == "escape" then -- quit is always the last check
love.event.push("quit")
end
end
function love.load()
audioSource = love.audio.newSource("audioFile.mp3")
love.audio.play(audioSource)
text = ">: "
status = "AUTO-STARTED"
end
function love.draw()
love.graphics.printf(text, 0, 0, 800)
love.graphics.printf(status, 100, 100, 800)
end
About the api -- Löve is quite cool, but I wish it has some short example underneath each of the functions so it's clear how to use and call each correctly.
Thanks.
There is a story of a farmer whose horse ran away. That evening the neighbors gathered to commiserate with him since this was such bad luck.
He said, "May be." Continued...
--snip
x, y, z = love.audio.getPosition()
text = text .. string.x
text = text .. string.y
text = text .. string.z
--snip
You assign the result of getPosition to (global) x, y and z, but then try to use it as string.x, string.y and string.z, that won't work. You could directly append x, y and z, or if you really want to make sure it's converted to a string, use tostring(x) (same for y and z, of course). In any case, getPosition isn't the right function.
Thanks. I'm pretty new to lua and brand new to löve, but it's really hard to abstain until my lua skills have come of age.
Here's what I did with your help. It works nice
function love.keypressed(key)
if key == "f1" then
love.audio.pause(audioSource)
position = audioSource:tell( "seconds" )
status = "PAUSED"
end
if key == "f2" then
love.audio.resume(audioSource)
-- NOTE TO FUTURE SELF:
-- Put resume / pause in array. Call array index, then index
-- switch so if key is pressed again, result is different.
status = "RESUMED"
end
if key == "escape" then -- quit is always the last check
love.event.push("quit")
end
end
function love.load()
audioSource = love.audio.newSource("audioFile.mp3")
love.audio.play(audioSource)
text = "Last paused at: "
status = "AUTO-STARTED"
end
function love.draw()
love.graphics.printf(text .. tostring(position), 10, 0, 800)
love.graphics.printf(status, 10, 25, 800)
end
There is a story of a farmer whose horse ran away. That evening the neighbors gathered to commiserate with him since this was such bad luck.
He said, "May be." Continued...
if key == "f2" then
playPause = {love.audio.pause(audioSource), love.audio.resume(audioSource)}
controlPress = playPause[1] -- execute the index function
playPause[1], playPause[2] = playPause[2], playPause[1] -- swap table index
status = "PLAY/PAUSE"
end
Is it my löve code or my index switch code?
Thanks.
There is a story of a farmer whose horse ran away. That evening the neighbors gathered to commiserate with him since this was such bad luck.
He said, "May be." Continued...
With this you first pause the source, store the returned value (none) in playPause[1], then resume the source and store the returned value (none) in playPause[2], so it's the LÖVE code
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
if key == "f2" then
if playPause[1] == "pause" then
love.audio.pause(audioSource)
else
love.audio.resume(audioSource)
end
playPause[1], playPause[2] = playPause[2], playPause[1] -- swap table index
status = "PLAY/PAUSE"
end
...moving playPause = {"pause", "play"} to the load() area.
There is a story of a farmer whose horse ran away. That evening the neighbors gathered to commiserate with him since this was such bad luck.
He said, "May be." Continued...
--in love.load()
playing = true
--in Keypressed
if key == 'f2' then
if playing then -- playing is true, so this is a valid condition and the chunk below will be executed
love.audio.pause(Source)
elseif not playing then --the elseif is useless, for if play is not true it is surely false
love.audio.resume(Source)
end
playing = not playing --if playing is true it becomes false, if it's false it becomes true: 'not' changes a variable between true and false
end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics