So I got everything working ok (I think) for the plugin I just released but I did come across a few odd behaviors which I'll list here for others benefit or they might be things that need fixing.
My plugin triggers off the TrackChanging event. When right clicking a song and selecting "Play Now", Musicbee waits for my process to finish before playing the song. All good. It doesn't matter if the player was currently stopped or in the middle of playing another song. Musicbee would wait for the process to finish.
But when it gets to the end of the song and TrackChanging triggers again, this time it doesn't wait and starts playing the next song before my process is finished. Not so good.
So I tried the following
Player_PlayPause()
//run speak process
Player_PlayPause()
Due to when TrackChanging triggers, this resulted in the player pausing right at the end of the song, the speak process occurs and when the Player_PlayPause() command runs again is where things go a bit bonkers.
What I expect to happen - player resumes and switches to the next song and starts playing it.
What happens - The player starts playing the song that just played again from the start. The speaker icon in the "Playing tracks" element displays on the next song. The info listed in the player controls panel is of the next song but the progress bar and play timer don't move. If I move the slider, the song playing pauses as if it's about to play from where I jumped the slider to but it doesn't, it just keeps playing from where it was originally up to.
It's as if Musicbee thinks it moved to the next song but keeps playing the previous one. Sometimes it also seemed to play the 2 songs at once.
To get around it I just had to do some player status checks and used Player_PlayNextTrack() instead of Player_PlayPause to resume the player. That successfully kicked it over the next song and everything worked as is should.