love.audio.newSource Cannot use full path

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
elfrea
Prole
Posts: 8
Joined: Fri Jan 06, 2023 11:31 pm

love.audio.newSource Cannot use full path

Post by elfrea »

Hi, i've been messing with the audio lib, and i could make it work no problem.
I can load a song if i give a path like : "music/music.ogg" which is located in "E:\lovegame"
if I give it the full path : "E:\lovegame\music\music.ogg" or "E:/lovegame/music/music.ogg", I always get the File not found error.
in other words:

printCWD :
E:\lovegame\

love.audio.newSource("music\music.ogg")
OK

love.audio.newSource("E:\lovegame\music\music.ogg")
Crash (File not found)

I even have a function to check wheter or not a file exists on the file system and if i check:
isFileExists("E:\lovegame\music\music.ogg")
True

Am i missing something or is it a bug with newSource() ?
User avatar
GVovkiv
Party member
Posts: 688
Joined: Fri Jan 15, 2021 7:29 am

Re: love.audio.newSource Cannot use full path

Post by GVovkiv »

elfrea wrote: Sun Jan 08, 2023 8:36 pm Hi, i've been messing with the audio lib, and i could make it work no problem.
I can load a song if i give a path like : "music/music.ogg" which is located in "E:\lovegame"
if I give it the full path : "E:\lovegame\music\music.ogg" or "E:/lovegame/music/music.ogg", I always get the File not found error.
in other words:

printCWD :
E:\lovegame\

love.audio.newSource("music\music.ogg")
OK

love.audio.newSource("E:\lovegame\music\music.ogg")
Crash (File not found)

I even have a function to check wheter or not a file exists on the file system and if i check:
isFileExists("E:\lovegame\music\music.ogg")
True

Am i missing something or is it a bug with newSource() ?
https://love2d.org/wiki/love.filesystem
In short, at current love 11.4, love filesystem functions is sandboxed to game "save" path and source. So you can't write/read content files outside of that sandbox.

Code: Select all

love.audio.newSource("E:\lovegame\music\music.ogg")
Can't found file because, for this function, you trying to access "E:\lovegame\music\music.ogg" file inside source/save directory, which doesn't exist (because, yet again, love filesystem function will look from source and save path).
In love 12.0 filesystem will be less restricted so you can wait for it (or build from source wip version, if you know how to) or you can try use libraries such as https://github.com/EngineerSmith/nativefs, that can access any file or directory anywhere, if you need. If you just want to play sounds/other assets from source directory, then there shouldn't be any reason try to get files outside of source/save path
elfrea
Prole
Posts: 8
Joined: Fri Jan 06, 2023 11:31 pm

Re: love.audio.newSource Cannot use full path

Post by elfrea »

Ok thanks everyone, im gonna wait for v12.
Actually what im doing is not exactly a game, its a tilemap editor with an audio player included in it, so i wanted to be able to load any song on my computer. but its ok, ive changed it so it scans all files in a music directory instead, so I just have to copy all the songs i want in that directory.
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: love.audio.newSource Cannot use full path

Post by Andlac028 »

elfrea wrote: Sun Jan 08, 2023 9:06 pm Ok thanks everyone, im gonna wait for v12.
Actually, you can build it from source (branch 12.0-development on Github repo), or if you are signed in Github, you can download artifacts from latest commit here
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.audio.newSource Cannot use full path

Post by slime »

Just to be clear: your code won't work as-is in any love version including love 12.

love 12 adds the ability to mount full platform-specific paths to love's virtual filesystem via love.filesystem.mountFullPath, rather than allowing arbitrary platform-dependent paths to be used in any API that takes a filepath. (i.e. you have to mount a folder to the virtual filesystem first, and then use a path based on the mount point parameter you've given to mountFullPath.)
elfrea
Prole
Posts: 8
Joined: Fri Jan 06, 2023 11:31 pm

Re: love.audio.newSource Cannot use full path

Post by elfrea »

ok thanks but thats allright i dont use the love filesystem, built my own lib instead
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Hydrogen Maniac, Semrush [Bot] and 6 guests