File not found, but it's exist

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.
love2dluacode
Prole
Posts: 7
Joined: Sun Mar 20, 2022 11:04 am

File not found, but it's exist

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: File not found, but it's exist

Post 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
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.
love2dluacode
Prole
Posts: 7
Joined: Sun Mar 20, 2022 11:04 am

Re: File not found, but it's exist

Post 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)
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: File not found, but it's exist

Post 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.
love2dluacode
Prole
Posts: 7
Joined: Sun Mar 20, 2022 11:04 am

Re: File not found, but it's exist

Post 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)
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: File not found, but it's exist

Post by MrFariator »

I'm afraid you'll have to post your code.
love2dluacode
Prole
Posts: 7
Joined: Sun Mar 20, 2022 11:04 am

Re: File not found, but it's exist

Post 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

User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: File not found, but it's exist

Post 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?
obey
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: File not found, but it's exist

Post 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
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: File not found, but it's exist

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 6 guests