Author Topic: Delegates not firing  (Read 3982 times)

jastill

  • Guest
I am really new to this and I am trying to figure out the basics of this API as the simple tutorials are badly commented.

How are we meant to use the delegate?

Are we meant to set them up in the Initialize:

  public PluginInfo Initialise(IntPtr apiInterfacePtr)
        {
            mbApiInterface = new MusicBeeApiInterface();
            mbApiInterface.Initialise(apiInterfacePtr);
            mbApiInterface.Player_Stop = new Player_ActionDelegate(Player_ActionTest);
           mbApiInterface.Player_PlayPause = Player_ActionTest;
            //....
        }

or in the start up of:
ReceiveNotification(string sourceFileUrl, NotificationType type) {}


My Player_ActionTest method is really simple:

 public bool Player_ActionTest()
        {
            MessageBox.Show("PLAYER STOPPED");
            return true;
        }

yet it will never fire when I click the play/pause or stop buttons.
Last Edit: August 10, 2013, 05:08:55 AM by jastill

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34369
i suggest you have a look at some of the open source plugins such as the Additional Tagging tools plugin, Android remote or the Lyrics Reloaded plugin.
Even the shell that comes with the API interface pack works as is.
You only need to call the Initialise() function - it assigns the api interface function pointers

  public PluginInfo Initialise(IntPtr apiInterfacePtr)
        {
            mbApiInterface = new MusicBeeApiInterface();
            mbApiInterface.Initialise(apiInterfacePtr);
           mbApiInterface.Player_Stop = new Player_ActionDelegate(Player_ActionTest);
           mbApiInterface.Player_PlayPause = Player_ActionTest;

           // to receive player notifications
           about.ReceiveNotifications = ReceiveNotificationFlags.PlayerEvents;

        }

and depending on what you want to do
        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            // perform some action depending on the notification type
            switch (type)
            {
                case NotificationType.PluginStartup:
                    // perform startup initialisation
                case NotificationType.PlayStateChanged:
                    if (mbApiInterface.Player_GetPlayState()== PlayState.Stopped)
                    {
                        MessageBox.Show("PLAYER STOPPED");
                    }

            }

to stop the player you would call:
mbApiInterface.Player_Stop();