Page 1 of 3

File not found, but it's exist

Posted: Sun Mar 20, 2022 11:11 am
by love2dluacode
Hello, i tried to make a game that plays videos with videos that are not in .love file. Here's my code:

Code: Select all

function love.load()
  directory = love.filesystem.getWorkingDirectory()
end
function love.draw()
  video = love.graphics.newVideo(directory .. "/videos/test.mp4")
  video:play()
end
Sorry if that thread is alerady exists, i just don't found it.

Re: File not found, but it's exist

Posted: Sun Mar 20, 2022 3:55 pm
by zorg
Löve's own filesystem is sandboxed; by default, you can only access two places with it:
- wherever your main.lua is,
- if you defined an identity, then a save folder in a specific place.

On windows (not sure about other OS-es), if you fuse your .love file to the executable, then you can also mount the source base directory, where the executable is, and also load files from that location.

If you need any other location, i'd suggest using the library NativeFS: https://github.com/EngineerSmith/nativefs

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 11:45 am
by love2dluacode
zorg wrote: Sun Mar 20, 2022 3:55 pm Löve's own filesystem is sandboxed; by default, you can only access two places with it:
- wherever your main.lua is,
- if you defined an identity, then a save folder in a specific place.

On windows (not sure about other OS-es), if you fuse your .love file to the executable, then you can also mount the source base directory, where the executable is, and also load files from that location.

If you need any other location, i'd suggest using the library NativeFS: https://github.com/EngineerSmith/nativefs
Still doesn't work (with nativefs)

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 11:55 am
by MrFariator
Can you describe your use case a bit more? Would love.filedropped for instance work if you need to implement a general purpose video player, or is there some other reason to loading files outside the fused executable?

You also don't really say what's wrong with nativefs, so hard to help troubleshooting there.

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 11:57 am
by love2dluacode
MrFariator wrote: Mon Mar 21, 2022 11:55 am Can you describe your use case a bit more? Would love.filedropped for instance work if you need to implement a general purpose video player, or is there some other reason to loading files outside the fused executable?

You also don't really say what's wrong with nativefs, so hard to help troubleshooting there.
it's still saying that file not found (nativefs)

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 11:57 am
by MrFariator
I'm afraid you'll have to post your code.

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 11:58 am
by love2dluacode
MrFariator wrote: Mon Mar 21, 2022 11:57 am I'm afraid you'll have to post your code.

Code: Select all

function love.load()
  local nativefs = require("nativefs")
  directory = nativefs.getWorkingDirectory()
end
function love.draw()
  video = love.graphics.newVideo(directory .. "/videos/test.mp4")
  video:play()
end


Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 1:48 pm
by BrotSagtMist
You need to draw the video, playing it does nothing on its own:

Code: Select all

video = love.graphics.newVideo(directory .. "/videos/test.mp4")
video:play()
function love.draw()
  love.graphics.draw(video)
end
Also you dont want to create a new video file on every frame.

Question for the others:
It is possible to create file handles using the normal io functions from luijit without the löve path restrictions.
It is further possible to create video objects using file handles using love.video.newVideoStream.
But the file handle types seem to be incompatible.
Is there a way to convert the io file handle into a löve type handle?
Or is there a way to feed generated data to a to the löve file handle creator?
I see there is love.filesystem.newFileData but i fail to see a way to use that file data as a file.
In my mind it reads like a construction of newVideo(newVideoStream(newFiledata(io.open(path):read(*a)))) should work for this case. (Of course a horrible decision for a video)
I mean why else is there a file data constructor if there is no use for it?

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 2:38 pm
by ReFreezed
love2dluacode wrote: Mon Mar 21, 2022 11:58 am

Code: Select all

function love.load()
  local nativefs = require("nativefs")
  directory = nativefs.getWorkingDirectory()
end
function love.draw()
  video = love.graphics.newVideo(directory .. "/videos/test.mp4")
  video:play()
end
You're still trying to use an absolute path when using LÖVE's API. You would need to read the contents of the file using e.g. NativeFS, and then make LÖVE create the video object from the read data (as opposed to having LÖVE read the file directly). However, love.graphics.newVideo doesn't allow you to give it any data directly as far as I can tell (which is different from other parts of LÖVE's API), so you have to use the love.filedropped callback like MrFariator said to access the file or, less optimally, copy the video file you're trying to play to the save directory first and let love.graphics.newVideo load it from there.

Code: Select all

-- Probably your best option:
function love.filedropped(file)
	video = love.graphics.newVideo(file)
	video:play()
end
function love.draw()
	if video then
		love.graphics.draw(video)
	end
end

Re: File not found, but it's exist

Posted: Mon Mar 21, 2022 7:03 pm
by MrFariator
As ReFreezed said, love.graphics.newVideo still uses the relative paths that LÖVE's file system uses by default; passing absolute paths doesn't work. However, reading the wiki, love.graphics.newVideo can also take in a VideoStream object, which can be constructed from a File object.

So using nativefs, the steps would roughly be:
1. Read the contents of your video file using nativefs
2. Create a File object from those contents (not sure about the best approach here, or if steps 1 and 2 can be combined somehow)
3. Pass the File object to love.video.newVideoStream
4. Pass the VideoStream object to love.graphics.newVideo
5. Play the video

Pretty convoluted (and inefficient), I know, but LÖVE's filesystem is just not built around handling arbitrary file locations. Again, I'd like to ask what the specific reason for arbitrary video playback might be, or whether love.filedropped can be used or not.