WATERMeDIA: Multimedia API

WATERMeDIA: Multimedia API

551k Downloads

Cannot load VLC installed via Flatpak

Mark6O9 opened this issue ยท 13 comments

commented

My friend and I were going to play around with this mod on their mod pack, but they told me that videos don't work. Me testing it in a single player world showed that videos don't work except images do work. We both think it could just be an issue for Linux and Windows is the only way to get this mod to work. However we also came to the theory that it just needs to be pointed to VLC on Linux.

commented

Log from Prism Launcher:

message.txt

commented

VLC is Installed
VLC Is installed

commented

Images for proof:

Video Link:
video link
2024-05-31_13 15 18

Image Link:
image link
2024-05-31_13 16 30

commented

you installed VLC via flatpak or Pakman?
sadly if was the case i can't give you support

consider use apt instead, because flatpak have a sandbox filesystem that doesn't let other things be readed.

commented

i transfered the issue to WATERMeDIA because the issue is for that lib

commented

you installed VLC via flatpak or Pakman? sadly if was the case i can't give you support

consider use apt instead, because flatpak have a sandbox filesystem that doesn't let other things be readed.

I installed it via flatpak

commented

you installed VLC via flatpak or Pakman? sadly if was the case i can't give you support

consider use apt instead, because flatpak have a sandbox filesystem that doesn't let other things be readed.

Can confirm, this issue occurs with apt anyways. I'm on Debian 12 latest with VLC installed via apt and I still cannot view videos.

commented

you installed VLC via flatpak or Pakman? sadly if was the case i can't give you support

consider use apt instead, because flatpak have a sandbox filesystem that doesn't let other things be readed.

Another thing, this isn't true! Flatpak just runs applications in a sandbox environment to protect users. Whilst the files still persist on your drive and can be accessed (for example, atlauncher via Flatpak is located at /home/.var/app/com.atlauncher.ATLauncher/), Flatpak ensures applications don't have every permission under the sun and can nuke everything. However, Watermedia knows of flatpak (as shown in the DIRECTORIES variable) so that isn't the issue here!

The issue (i assume from looking at the other directories) is because Watermedia isn't looking inside the vlc directory in x64_64-linux-gnu at https://github.com/SrRapero720/watermedia/blob/4cd8a933990a5dbbc4d2d80d5f2483e96c5811d4/lib-vlcj/src/main/java/uk/co/caprica/vlcj/discovery/provider/LinuxWellKnownDirectoryProvider.java#L31

Adding the directory: /usr/lib/x86_64-linux-gnu/vlc should fix this I believe!

commented

Actually, i'll just PR this myself to test that this is right.

commented

So, I was wrong. Upon further inspection, it turns out that, not only is listFiles() unreliable (see https://github.com/SrRapero720/watermedia/blob/4cd8a933990a5dbbc4d2d80d5f2483e96c5811d4/lib-vlcj/src/main/java/uk/co/caprica/vlcj/discovery/strategy/BaseNativeDiscoveryStrategy.java#L120 and https://stackoverflow.com/questions/28984430/file-listfiles-does-not-work-on-linux), but, your for loop in the find function (https://github.com/SrRapero720/watermedia/blob/4cd8a933990a5dbbc4d2d80d5f2483e96c5811d4/lib-vlcj/src/main/java/uk/co/caprica/vlcj/discovery/strategy/BaseNativeDiscoveryStrategy.java#L118) simply doesn't finish!

Pulling your 2.0.x branch and changing the find function to be:

private String find(String directoryName) {
        try(DirectoryStream<Path> rootFolder = Files.newDirectoryStream(getSymLinkPathOrSelf(Paths.get(directoryName)).toPath())) {
            if (rootFolder == null) {
                File rootFile = new File(directoryName);
                LOGGER.debug(IT, "Cannot search on '{}', exists: {} - isDirectory: {} - canRead: {} - canExecute: {} ", directoryName, rootFile.exists(), rootFile.isDirectory(), rootFile.canRead(), rootFile.canExecute());
                return null;
            }

            LOGGER.info(IT, "Searching EPIC FILE on '{}'", directoryName);

            Set<String> matches = new HashSet<>(patternsToMatch.length);
            for (Path mainFile : rootFolder) {
                System.out.println("File name: " + mainFile.getFileName().toString());

                if (Files.isDirectory(mainFile)) continue;
                // check files directly
                for (Pattern pattern : patternsToMatch) {
                    System.out.println("Pattern to match: " + pattern.pattern());
                    Matcher matcher = pattern.matcher(mainFile.getFileName().toString());
                    if (matcher.matches()) {
                        System.out.println("Matches!");
                        // A match was found for this pattern (note that it may be possible to match multiple times, any
                        // one of those matches will do so a Set is used to ignore duplicates)
                        matches.add(pattern.pattern());
                        if (matches.size() == patternsToMatch.length) {
                            return directoryName;
                        }
                    }
                }
            }

            System.out.println("Looped successfully!");
        } catch (Exception ignored) {
            System.out.println("EXCEPTION!!");
        }

        return null;
    }

Sees the Looped successfully! never fire when looping through /usr/lib/x86_64-linux-gnu!

[04/06/2024 19:52:51 pm] [modloading-worker-0/INFO] Searching on '/usr/lib/x86_64-linux-gnu'
[04/06/2024 19:52:51 pm] File name: libpipewire-0.3.so.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libxml2.so.2
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libgstvideo-1.0.so.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libGLdispatch.so.0.0.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libGLX.so.0.0.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libgettextpo.so.0.5.9
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libgeoclue-2.so.0.0.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libcrypt.so.2
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libXt.so.6
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libSDL2-2.0.so.0.2800.5
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libmythes-1.2.so.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libquadmath.so.0.0.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libvorbisenc.so.2.0.12
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libxkbfile.so.1
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libnss_files.so.2
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libsystemd.so.0.37.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libunwind-setjmp.so.0
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libavcodec.so.60
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libanl.so.1
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: libpixman-1.so.0.42.2
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File name: dvb-format-convert
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] Pattern to match: libvlc\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] Pattern to match: libvlccore\.so(?:\.\d)*
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] File is libvlc.so.5? false
[04/06/2024 19:52:51 pm] WOAHHHHHH LINUX TIME!!

For more context, WOAHHHHHH LINUX TIME!! is fired when LinuxNativeDiscoveryStrategy is asked if its supported. You can also ignore the [04/06/2024 19:52:51 pm] File is libvlc.so.5? false as this log came from a second test where I actually saved the log, I just added that in-case it wasn't logging everything.

It seems like the for loop is being cutoff by something (forge preventing this from taking too long?) so Watermedia is unable to find the VLC file.

Taking the code into a standalone project:

public static Pattern[] patternsToMatch;

    public static void main(String[] args) {
        patternsToMatch = new Pattern[1];
        patternsToMatch[0] = Pattern.compile("libvlc\\.so(?:\\.\\d)*");

        try(DirectoryStream<Path> rootFolder = Files.newDirectoryStream(getSymLinkPathOrSelf(Paths.get("/usr/lib/x86_64-linux-gnu")).toPath())) {
            for (Path mainFile : rootFolder) {
                System.out.println("File name: " + mainFile.getFileName().toString());

                if (Files.isDirectory(mainFile)) continue;

                for (Pattern pattern : patternsToMatch) {
                    System.out.println("Pattern to match: " + pattern.pattern());
                    Matcher matcher = pattern.matcher(mainFile.getFileName().toString());
                    if (matcher.matches()) {
                        System.out.println("Matches!");
                    }
                }
            }
        } catch (Exception ignored) {
        }
    }

    private static File getSymLinkPathOrSelf(Path path) {
        if (!Files.isSymbolicLink(path)) return path.toFile();
        try {
            File symLink = Files.readSymbolicLink(path).toFile();
            return symLink;
        } catch (Exception ignored) {}
        return path.toFile();
    }

I can see it finds the file correctly and shows "Matches!"

File name: libvlc.so.5
Pattern to match: libvlc\.so(?:\.\d)*
Matches!

I would heavily suggest you find out why in your own time for your next version. For now, I'm going to add a PR that will try see if VLC exists in specific files and use that, allowing this as a backup (that will most likely fail).

commented

Sees the Looped successfully! never fire when looping through /usr/lib/x86_64-linux-gnu!

Thats because when the SET is done (all are matched) the for loop is interrumped by the return block inside of the Matches check
in your second piece of code, you added the "matches" logger, so that explains why doesn't looks like "loop was finished"

It seems like the for loop is being cutoff by something (forge preventing this from taking too long?) so Watermedia is unable to find the VLC file.

If forge or neoforge do that they probably will be totally avoided for modding, because that will lead in a tons of crashes. Forge bootstrapping is offthread, so isn't affecting any modloading process for other mods

Turns out, if you use ATLauncher via flatpak it doesn't see VLC files (should of guessed that before all this testing huh). In other words, @Mark6O9, make sure your ATLauncher isn't installed via Flatpak otherwise you won't be able to see Videos!

No matters even if you install Minecraft out Flatpak, you cannot open VLC files if are managed by the flatpak FileSystem
Flatpack FS hides all theirs files for the OS FileSystem, even Flatpak installed stuff cannot see other Flatpak installed stuff.

Going forward, @SrRapero720, you should add a notice to your README that states this mod does NOT work with any minecraft launcher/instance from Flatpak.

I was forgetting about do that for a long time. i'll make sure i add it on readme (or wiki)

commented

God this has been a nightmare, anyways, I've figured it out without needing a PR!

Turns out, if you use ATLauncher via flatpak it doesn't see VLC files (should of guessed that before all this testing huh). In other words, @Mark6O9, make sure your ATLauncher isn't installed via Flatpak otherwise you won't be able to see Videos!

Going forward, @SrRapero720, you should add a notice to your README that states this mod does NOT work with any minecraft launcher/instance from Flatpak.

Hope this helps!

commented

For future references, VLC cannot be loaded if was installed via Flatpak, neither if launcher/minecraft was installed via Flatpak
Both have to be installed using other package managers (like APT-GET)

No, i cannot give support due to flatpak FileSystem limitations. PRs for workarrounds are welcome but i have no plans to support a sandboxed installation