getmusicbee.com

Support => Developers' Area => Topic started by: 2MuchToo on March 09, 2020, 12:38:49 AM

Title: Newbie here, stuck on tutorial
Post by: 2MuchToo on March 09, 2020, 12:38:49 AM
Hi!  Thanks to Steven and this community for the great player app.

I am interested in making a plugin.  I'm a total C# newb and it's a few years since I did coding at all. So I've been following the tutorial, but got stuck.  I believe the issue is where methods belong in the code, specifically createMenuItem() and MenuClicked, and/or the call to mbApiInterface.createmenuitem()


(https://i.imgur.com/EKpyG6Y.png)



If I have the createmenuitem call in the Initialize method as per the instructions (highlighted), then
If createMenuItem() and MenuClicked are outside the Initialize code block, I get “Unreachable code detected”.  Everything still runs but there's no menu created.

If the 2 methods are inside the Initialize code block I get “The modifier private is not valid for this item.” Again it doesn't crash but no menu.

If I put mbApiInterface.createmenuitem() outside of Initialize method, I get “The name mbApiInterface.createmenuitem() does not exist in the current context.

I imagine this is a very simple error related to the flow of the code, but I am stumped. If someone could point me right it would be much appreciated!

Thanks!
Title: Re: Newbie here, stuck on tutorial
Post by: karaluh on March 23, 2020, 09:10:57 PM
Same issue here. The code compiles, there are no warnings, but there is no menu entry either.

Code
namespace MusicBeePlugin
{
    public partial class Plugin
    {
        private MusicBeeApiInterface mbApiInterface;
        private PluginInfo about = new PluginInfo();

        public PluginInfo Initialise(IntPtr apiInterfacePtr)
        {
          
            [some default code removed]

            createMenuItem();

            return about;
        }


        [some default code removed]

        private void createMenuItem() {
            mbApiInterface.MB_AddMenuItem("mnuTools/Start My Plugin", "HotKey For Start My Plugin", menuClicked);
        }

        private void menuClicked(object sender, EventArgs args) {
            Form1 myForm = new Form1(); myForm.Show();
        }
}
Title: Re: Newbie here, stuck on tutorial
Post by: karaluh on April 06, 2020, 08:10:46 PM
My issue was my stupidity. I forgot to enable the plugin :P
Title: Re: Newbie here, stuck on tutorial
Post by: Briter on October 23, 2021, 07:18:34 AM
LOL I have the same problem. (Solved)

It was API calling. You call an API before the API calling.
You need to use "createMenuItem();" after "mbApiInterface.Initialise(apiInterfacePtr);" in Initialise method.
Yeah. That's all. EZ fixed.  8)