Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - simshaun

Pages: 1
1
Plugins / Remember Last Position of each track
« on: January 11, 2019, 08:09:23 PM »
Hi,

I'm using MusicBee solely for listening to Audiobooks, and I wanted it to remember where I left off on each book (I listen to multiple books at a time), so I wrote this plugin.

https://github.com/simshaun/musicbee-audiobook-position-tracker

2
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;
            }
        }

Pages: 1