Log in to reply

LemonUI Music Player for wav format.

  • With fantastic support from @JustDancePC , @Niziul , and @Jitnaught, with their combined knowledge and participation a music player for wav format songs is now possible and open source with LemonUI.

    The final code is from @Niziul but @JustDancePC's version was just as functional. @Jitnaught provided support and I learned quite a few new things about scripting from him as well.

    This code is best suited for those with beginner to intermediate LemonUI and C# skills - in other words you'll know what to do with it.

    Description: wav music files are placed in a folder of your choice, subfolder of scripts in this code. The code will loop through all the wav files in your music folder, it will then put the file names in the LemonUI player. So nothing is hardcoded other than the path to your music. Spawn key is shift + T but given this is open source, do whatever you want.

    If anyone figures out how to play mp3s (NAudio), it would be greatly appreciated if you shared your solution.

    using GTA;
    using LemonUI;
    using LemonUI.Menus;
    using System.IO;
    using System.Media; //for playing .wav
    namespace MusicPlayer
        internal class Class2 : Script
            public Class2()
                var objectPool =
                    new ObjectPool();
                var nativeMenu =
                    new NativeMenu(title: "Music Player",
                                   subtitle: "",
                                   description: "")
                        Visible =
                        UseMouse =
                nativeMenu.Shown += (o, e) =>
                    var allSongName =
                    for (var i = 0; i < allSongName.Length; i++)
                            .Add(new NativeItem(Path
                    nativeMenu.ItemActivated += (o2, e2) =>
                Tick += (o, e) =>
                KeyUp += (o, e) =>
                    if (e.Shift && e.KeyCode is System.Windows.Forms.Keys.T)
                            .Visible = !nativeMenu.Visible;
                Aborted += (o, e) =>
            private void PlaySong(string songPath)
                GTA.UI.Notification.Show($"Playing this song: ~y~{Path.GetFileNameWithoutExtension(songPath)}", true);
                new SoundPlayer(songPath).Play();
            private string[] GetPathOfAllSongs()
                var pathToTheScriptFolder =
                var pathOfAllTheSongsFoundInTheScriptFolder =
                        .GetFiles(path: pathToTheScriptFolder,
                                  searchPattern: "*wav");
                return pathOfAllTheSongsFoundInTheScriptFolder;

  • Just in passing, anyone thinking they can just change the .mp3 extension to .wav is the solution, it's not.

    This method works fine with the proper codecs installed and an mp3 player like AIMP.

    However it will not work with the Windows SoundPlayer and C# (and yes I give it a shot).

  • @JohnFromGWN I managed to get it working with .mp3 files. Full code here. I don't think I did something different in the part where the music is played, maybe your files were corrupt or something, idk

    Video here

  • @JustDancePC This looks fantastic but can i ask you for the download link for your NAudio files as they seem to be on many different sites. When I compiled I had dozens of invalid references related to NAudio.

  • @JohnFromGWN I downloaded it from the Nuget store. Basically, if you are developing a C# project, you can use the NugetPackageManager to download whatever packages you need (like NAudio), it will download and add the references for you, and even notify when updates are out. LemonUI and SHVDN are also available on the Nuget Store.

    Here is the Microsoft documentation on how to use the NugetPackageManager in Visual Studio.

    This tutorial is more complete.

  • @JustDancePC thank you, I got package, all reference issue resolved but 9 errors including one about language and some very surprising for example that ontick isn't valid. Will take a look when I have a chance.

  • @JustDancePC said in LemonUI Music Player for wav format.:

    @JohnFromGWN I managed to get it working with .mp3 files. Full code here. I don't think I did something different in the part where the music is played, maybe your files were corrupt or something, idk

    Video here

    One thing, the project was made using C# 10, so, if you copy code from there you might get some errors if your project is set up with an older version of C#, like C# 7.2, which is the default for .NET Framework projects.

    You can either change the syntax to comply with C# 7.2 or update your C# version

  • @JustDancePC I'm editing the csproj file as we speak.

    still getting error:
    Severity Code Description Project File Line Suppression State Error CS1617 Invalid option 'C# 10' for /langversion. Use '/langversion:?' to list supported values. MusicMenu M:\Animation\GTA V\VS2019_CS\musicmenu-main\MusicMenu\CSC 1 Active

    In passing for some reason I can't change the language from inside VS, the option is greyed out. So I researched and it said to edit the project file. But can't get it to work.


  • @JustDancePC
    So, I can't change the language from inside Visual Studio and editing the csproject file doesn't remove the error.

    I also made updates to VS 2019 - nothing helped.

    Is there anyway I can downgrade the configuration of your file to match ?

    If not I'll try an adapt your functions or just stay with the wav version.

    Once more thank you for all your time, effort, and patience! :)

  • @JustDancePC Ok i think i got it this time. changed langversion to "latest"

  • @JustDancePC Yes, I found that and I solved all the reference and compiler errors.

    I have my files in Music, all valid mp3s but still sadly can't get them to play. This time with error message.

    File not Found error? No reason for that. Files are there and in same path as in your code. \scripts\Music

    alt text

  • @JohnFromGWN If you say the files are there, then maybe, for some reason, it's looking in the wrong path? How about adding a subtitle that shows the path when you hit play, like a debug message, to see which path it's trying to use

  • @JustDancePC the previous code for the path worked, will compare them, folder hasn't changed. Thanks. Will check for a reference issue, one dealing with system.

  • @JustDancePC

    Forgot to mention the most important part. The menu is populated with my music files, therefore the path is correct.

    The error message is therefore bullshit. Something else is causing the issue.

  • @JohnFromGWN Ok, I know what the problem is. You forgot to copy the NAudio dlls to your scripts folder. That's why it's crashing everytime you try to play a song. The notification only shows you the file not found part, but if you open the full log, you will see it's because the dll is missing

  • @JustDancePC No it's there, unless it is a version issue. What version do you have? Mine is

    My guess is one of two things. Missing reference or the version language. Whaddya think?

    alt text

  • @JohnFromGWN
    I even removed all my scripts (and they are all personal scripts) to avoid conflicts. Tested and didn't make a difference.

    At least it compiles and loads and displays the files. Issue with audio.

    In my limited experience scripting, I've seen many error messages, at run time, which had absolutely nothing to do with the real issue. Code compiles, no errors, run the program and you get some BS message.

    In passing, when helping ppl troubleshoot GTA5 installations, I totally disregard their error messages. Only interested in log files and what they did.

    Hard to believe in 2022 that Microsoft can't support mp3s themselves.

    alt text

  • @JohnFromGWN Show me your SHVDN log file

  • @JohnFromGWN Oh wait, you only copied one NAudio dll. You need all of them. There's like 4 or 5

  • @JustDancePC
    [16:23:18] [DEBUG] Loading assembly NAudio.dll ...
    [16:23:18] [INFO] Found 0 script(s) in NAudio.dll.

  • @JustDancePC ok, that makes sense. names please? and where is the package, github?

  • @JohnFromGWN You installed them already. When you compile the project, along your dll and pdb file, there's also a bunch of NAudio dlls. You copy all of them

  • @JustDancePC in the project folder?

Log in to reply

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.