getmusicbee.com

Support => Developers' Area => MusicBee API => Topic started by: simshaun on January 11, 2019, 09:26:04 AM

Title: Player_SetPosition() triggers NotificationType.TrackChanged?
Post by: simshaun on January 11, 2019, 09:26:04 AM
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;
            }
        }
Title: Re: Player_SetPosition() triggers NotificationType.TrackChanged?
Post by: boroda on January 11, 2019, 10:05:53 AM
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).
Title: Re: Player_SetPosition() triggers NotificationType.TrackChanged?
Post by: simshaun on January 11, 2019, 07:24:27 PM
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?
Title: Re: Player_SetPosition() triggers NotificationType.TrackChanged?
Post by: simshaun on January 11, 2019, 08:05:34 PM
Got it going! https://github.com/simshaun/musicbee-audiobook-position-tracker
Title: Re: Player_SetPosition() triggers NotificationType.TrackChanged?
Post by: boroda on January 11, 2019, 08:54:06 PM
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.