getting the length of a source and some more questions

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
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

getting the length of a source and some more questions

Post by Doctory »

how would i get the length of a source? i need it because im making a music player
i have all my music in a folder, how would i make a source for each and everyone of them without actually knowing the name of the file?
and how would i get the extension of a file, ex .mp3?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: getting the length of a source and some more questions

Post by Robin »

Doctory wrote:how would i get the length of a source?
AFAIK, you can only get the length of [wiki]SoundData[/wiki], so you would do something like this:

Code: Select all

local sd = love.sound.newSoundData(sound_filename)
local length = sd:getSampleCount() / sd:getSampleRate()
local source = love.audio.newSource(sd)
Doctory wrote:how would i make a source for each and everyone of them without actually knowing the name of the file?
With [wiki]love.filesystem.getDirectoryItems[/wiki].
Doctory wrote:and how would i get the extension of a file, ex .mp3?
Something like:

Code: Select all

local extension = filename:sub((filename:find(".", 1, true))) -- parentheses important
Help us help you: attach a .love.
User avatar
Doctory
Party member
Posts: 441
Joined: Fri Dec 27, 2013 4:53 pm

Re: getting the length of a source and some more questions

Post by Doctory »

Robin wrote:-snip-
thanks robin
Post Reply

Who is online

Users browsing this forum: No registered users and 191 guests