Skip to content

The Media constructor that takes a raw string path errors if given a file path with forward slashes on Windows

_mediaPlayer.Media = new Media(_libVLC, Application.dataPath + "/HitboxCrime.mp4", FromType.FromPath);

The above uses a local file path with forward slashes on Windows, both in Application.dataPath and in the suffix part. That will cause the following cryptic VLC error:

VLCException: Failed to perform instanciation on the native side. Make sure you installed the correct VideoLAN.LibVLC.[YourPlatform] package in your platform specific project
LibVLCSharp.Internal..ctor (System.Func`1[TResult] create, System.Action`1[T] release) (at /builds/videolan/vlc-unity/tmp/lvs/src/LibVLCSharp/Internal.cs:37)
LibVLCSharp.Media..ctor (System.Func`1[TResult] create, System.Action`1[T] release, System.String[] options) (at /builds/videolan/vlc-unity/tmp/lvs/src/LibVLCSharp/Media.cs:166)
LibVLCSharp.Media..ctor (LibVLCSharp.LibVLC libVLC, System.String mrl, LibVLCSharp.FromType type, System.String[] options) (at /builds/videolan/vlc-unity/tmp/lvs/src/LibVLCSharp/Media.cs:183)
MinimalPlayback.Update () (at Assets/VLCUnity/Demos/Scripts/MinimalPlayback.cs:97)

Note: This problem does not happen if you replace all forward slashes with backslashes:

_mediaPlayer.Media = new Media(_libVLC, Application.dataPath.Replace('/', '\\') + "\\HitboxCrime.mp4", FromType.FromPath);

The problem also does not happen if you use the Uri constructor for Media:

_mediaPlayer.Media = new Media(_libVLC, new Uri(Application.dataPath + "/HitboxCrime.mp4"));

Expected result: Setting a new Media with a local file path with forward slashes on Windows works without error (like most other Windows apps).

Actual result: The above error.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information