Author Topic: Notification TrackChanging not triggering  (Read 2162 times)

BoringName

  • Sr. Member
  • ****
  • Posts: 916
Version - 3.6.9139 P

These are the flags being used - about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);

Everything else seems to be triggering fine but TrackChanging does not.

It doesn't matter if I manually select a different track or let the current track end and move onto another, this notification doesn't get triggered.

In case it helps. When a track changes I'm trying to pause the track, do something and then resume playing the track. But using the TrackChanged notification allows a tiny amount of the track to play before Player_PlayPause() comes into effect so I think TrackChanging will be the better option if I can get it to trigger.

edit: Just to make sure this will do what I want.

I'm hoping the TrackChanging notification provides the sourceFileUrl of the track being changed to and if I use NowPlaying_GetFileUrl() with that notification it will return the Url of the track that was previously playing.
Last Edit: January 10, 2025, 09:52:16 AM by BoringName

Mayibongwe

  • Sr. Member
  • ****
  • Posts: 1733
  • Heal The World
These are the flags being used - about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);
Everything else seems to be triggering fine but TrackChanging does not.
Tested and confirmed.
Strength and Honour (2025)

BoringName

  • Sr. Member
  • ****
  • Posts: 916
Tested and confirmed.

Thanks. Good to know it wasn't me just me being an idiot, which is usually the case with these types of things.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976
this should work but note that its a synchronous event, so any delay on your side affects the playback
https://getmusicbee.com/patches/MusicBee36_Patched.zip

BoringName

  • Sr. Member
  • ****
  • Posts: 916
this should work but note that its a synchronous event, so any delay on your side affects the playback
https://getmusicbee.com/patches/MusicBee36_Patched.zip

It still doesn't appear to be triggering. Checked to make sure I updated it properly and the version listed is 3.6.9143 P

When I let a song play out and it switches to the next song, the only notification that triggers is still just TrackChanged.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976
thats the correct version and its working fine here. Infact i dont see how it would not be called.
Perhaps there is something in the error log?

BoringName

  • Sr. Member
  • ****
  • Posts: 916
thats the correct version and its working fine here. Infact i dont see how it would not be called.
Perhaps there is something in the error log?

Hmm. Nothing in the error log. I set it up to save all triggered events to a text file. Started Musicbee and set it to play the 2 songs listed in the playing tracks panel and let it finish.
These are the events that were listed in the file afterwards.
PluginStartup
MusicBeeStarted
PlayStateChanged
PlayStateChanged
TrackChanged
PlayStateChanged
PlayStateChanged
PlayCountersChanged
TrackChanged
PlayCountersChanged
NowPlayingListEnded
PlayStateChanged
PlayStateChanged

I just used type.ToString() in the first line of the RecieveNotification void. If TrackChanging triggered it should be listed but it isn't.

I'm stumped.

edit: This is the interface file I'm using. Maybe there is something wrong with it? MusicBeeInterface.cs
Last Edit: January 12, 2025, 04:48:47 AM by BoringName

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976

BoringName

  • Sr. Member
  • ****
  • Posts: 916

BoringName

  • Sr. Member
  • ****
  • Posts: 916
this should work but note that its a synchronous event, so any delay on your side affects the playback

This actually worked out better than I expected. I don't need to pause/play at all because Musicbee waits for what I'm doing to finish before it plays the track which is perfect.

edit: actually it's not full synchronous. When I first startup musicbee and play a song it waits until I've finished but when that song ends it only waits a few seconds and starts playing the next song even though my process hasn't finished.... I'll have a play around.
Last Edit: January 12, 2025, 09:38:43 AM by BoringName

BoringName

  • Sr. Member
  • ****
  • Posts: 916
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.

Steven

  • Administrator
  • Hero Member
  • *****
  • Posts: 34976
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.
yes thats what i would expect but you really need to implement your processing in another thread so it returns as quickly as possible. Otherwise i can just make it asynchronous like other events but that just means you might or might not receive it after the track has actually started playing, however it will be before the TrackChanged event

BoringName

  • Sr. Member
  • ****
  • Posts: 916
yes thats what i would expect but you really need to implement your processing in another thread so it returns as quickly as possible. Otherwise i can just make it asynchronous like other events but that just means you might or might not receive it after the track has actually started playing, however it will be before the TrackChanged event

All good, leave it as is. I'll have a crack at running it in a separate thread for the next version.