[SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
unixfreak
Citizen
Posts: 82
Joined: Thu Oct 15, 2015 6:25 am
Location: Bristol, UK
Contact:

[SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Post by unixfreak »

Hi, tried searching, and fiddling about but cannot find a way to do this.

As per; https://love2d.org/wiki/love.audio.rewind (which is now removed since 11.0)

An example why i'd like to find a way to do this; a player can collect a series of pickups (coins, gems or whatever), which all use the same sound effect that could be an entire second long. But you may pickup/collide with many objects in a single second, and then things sound very spam-like and noisy as you have duplicate sources spamming away.

This is what i had used previously, only requiring a single source;

Code: Select all

function sound:play(fx)
	love.audio.rewind(fx)
	fx:play()
end
What i currently have as a temporary workaround (very spammy and noisy), and i believe :clone() makes many duplicates of the same source;

Code: Select all

function sound:play(fx)
	fx:clone():play()
end
How can i recreate that previous behaviour without the love.audio.rewind() function?
User avatar
unixfreak
Citizen
Posts: 82
Joined: Thu Oct 15, 2015 6:25 am
Location: Bristol, UK
Contact:

Re: [SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Post by unixfreak »

Found a solution... turns out it was quite simple. Now it seems :stop() on an audio source automatically rewinds. Solved.

Code: Select all

function sound:play(fx)
	fx:stop()
	fx:play()
end
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [SOLVED] How can i rewind a sound source, now that love.audio.rewind(source) has been removed?

Post by zorg »

There's a simpler solution

Code: Select all

sound:seek(0)
This is functionally equivalent to the old source:rewind function, and it continues playing without you needing to call play, if it was playing already.
Me and my stuff :3True 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests