hudec117 / Mpv.NET-lib-

.NET embeddable video/media player based on mpv for WinForms and WPF
MIT License
139 stars 36 forks source link

When using MSIX packaging, the required files are not found #57

Open ptdev opened 1 year ago

ptdev commented 1 year ago

Hi, I'm having an issue using this library with a WPF app that I'm assuming is due to it being a MSIX packaged app but would appreciate it if anyone else could either confirm or deny it's an actual issue.

Mpv.NET (lib) Version Latest stable

Describe the bug This library seems to use relative paths to find the required files (dll, ytdl, lua hook script). But when using an MSIX packaged app, those relative paths always seem to begin at Windows\system32 and not the app's install folder. So, when the lib tries to find the files it fails as they are obviously not there.

I can pass the correct path for the mpv-1.dll by setting the second parameter of the MPVPlayer contructor to be: player = new MpvPlayer(PlayerHost.Handle, System.AppDomain.CurrentDomain.BaseDirectory + "\\lib\\mpv-1.dll") And that fixes the issue for that file

And also call the EnableYouTubeDl method with the correct path as a parameter: player.EnableYouTubeDl(System.AppDomain.CurrentDomain.BaseDirectory + "\\lib\\ytdl_hook.lua") And that fixes the issue for the lua script

But then another issue arises and that's the one I'm stuck on. Because it's the lua script itself that then tries to load the ytdl.exe and it's also apparently using a relative path and therefore it also tries to load it from windows\system32 and fails again. And since that's being done from inside the lua script, I can't do the same as above as I don't know how to pass the correct path (System.AppDomain.CurrentDomain.BaseDirectory) to the lua script so it finds it correctly.

To Reproduce Steps to reproduce the behavior:

  1. Create an app that uses an MSIX installer (https://learn.microsoft.com/en-us/windows/msix/desktop/desktop-to-uwp-packaging-dot-net)
  2. Follow the installation instructions on this repository to use mpv + ytdl
  3. Try to load a youtube video
  4. Setting the mpvloglevel to debug tells us that the lua script is not finding the ytdl.exe file. And adding some extra Debug statements shows that the lua script is looking inside c:\windows\system32\lib for the ytdl.exe file and not finding it.

Expected behavior Files should be found independently of it being run as a packaged MSIX app or as a regular app.

Cheers and thanks for developing this library.