Author Topic: Player_SetPosition() triggers NotificationType.TrackChanged?  (Read 182 times)

simshaun

  • Newbie
  • *
  • Posts: 8
Apologies if this is a dumb question, but I'm rather new to C# and trying to cobble together a plugin.

My goal is to store Player_GetPosition() at an interval. When the user changes to another track, load the stored position of that track. In other words, "remember where I left off" on a per-file basis.

I've nearly got it all working, except when I change to a new track in my now-playing list, I'm getting an infinite loop because Player_SetPosition() appears to be triggering `NotificationType.TrackChanged`.

Is there a different event I need to be using? Thanks in advance.

(shortened code:)
Code
        public void LoadSavedPosition()
        {
            try
            {
                var text = File.ReadAllText(GetPositionFilename());
                _mbApiInterface.Player_SetPosition(int.Parse(text));
            }
            catch (Exception)
            {
                // ignored
            }
        }

        public void ReceiveNotification(string sourceFileUrl, NotificationType type)
        {
            switch (type)
            {
                case NotificationType.TrackChanged:
                    LoadSavedPosition();
                    break;
            }
        }

boroda

  • Hero Member
  • *****
  • Posts: 3223
my solution for tag tools plugin (similar problem): store current track url in global string variable before setting new position, then compare current track url with stored 'previous' track url when you receive 'track changed' event (ignore the event if both url's are the same).

simshaun

  • Newbie
  • *
  • Posts: 8
Thanks! I think I've got it all working now after a lot of trial and error.

By the way, is there a better development workflow than doing this after every change? 1) Rebuild Solution in VS, 2) Close MusicBee, 3) Copy/paste DLL to MusicBee folder, 4) Reopen MusicBee?


boroda

  • Hero Member
  • *****
  • Posts: 3223
Thanks! I think I've got it all working now after a lot of trial and error.

By the way, is there a better development workflow than doing this after every change? 1) Rebuild Solution in VS, 2) Close MusicBee, 3) Copy/paste DLL to MusicBee folder, 4) Reopen MusicBee?
you cant do very much. personally I adjusted build path in VS to mb\plugins folder, but anyway I need to close mb before rebuilding solution and then reopen mb.