Sending Player info to a window

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

marceros
Posts: 25
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Hello!

I'm dealing with catching changes in the 'Now playing' list as events so I can change my display accordingly.

The playbackState fires when one track ends and the next one starts playing. The nowPlayingModified fires when I add a new track to the player. My problem is that I cannot find which events will fire when I remove a track or I move a track within the player. Are there events for those situations?

Thank you in advance,
Marcelo
drakinite
Posts: 848
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Sending Player info to a window

Post by drakinite »

Haven't tested to make sure, but both should fire with nowPlayingModified: https://www.mediamonkey.com/docs/api/fi ... ngModified
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
marceros
Posts: 25
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

drakinite wrote: Mon Jul 04, 2022 2:39 pm Haven't tested to make sure, but both should fire with nowPlayingModified: https://www.mediamonkey.com/docs/api/fi ... ngModified
Thank you for the prompt response. I think it doesn't work. I hope I'm wrong. I'll try again.

Meanwhile, I'm using SetTimeout to send a function that calls itself recursively and checks for changes in the player.

Thanks,
Marcelo
Ludek
Posts: 4652
Joined: Fri Mar 09, 2007 9:00 am

Re: Sending Player info to a window

Post by Ludek »

Hi Marcelo,
thanks for reporting, it really fails to work for re-order and deletions.

To be fixed as https://www.ventismedia.com/mantis/view.php?id=19266

Workaround is to listen 'change' event on app.player.getSongList()
https://www.mediamonkey.com/docs/api/cl ... etSongList
marceros
Posts: 25
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Thank you for the response!

Can you show me how the workaround line looks?

Maybe something like:

app.listen(app.player.getSongList(), 'change', eventFunction);

Thanks,
Marcelo
drakinite
Posts: 848
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Sending Player info to a window

Post by drakinite »

Yep. Though it may be a better idea to store the list as a variable first.

Code: Select all

let thisSongList = app.player.getSongList();
app.listen(thisSongList, 'change', function (changeType) {
	// do stuff
});
(I haven't tested that code, but it should work)
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
marceros
Posts: 25
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Maybe I understand now. So I'm actually checking the change in a list, not an event as I'm used to. Is it right?

And in that case, I have to set a loop where the list variable gets the new list and the "change event" does the rest.

Am I seeing it right?

Thank you!
drakinite
Posts: 848
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Sending Player info to a window

Post by drakinite »

marceros wrote: Thu Jul 21, 2022 2:14 pm And in that case, I have to set a loop where the list variable gets the new list and the "change event" does the rest.
No, no need for a loop. I was just giving a general coding suggestion. app.listen(app.player.getSongList(), ...) is still valid; but if you want to access thisSongList inside your event handler, you won't have to do app.player.getSongList() multiple times.

Code: Select all

app.listen(app.player.getSongList(), 'change', function (changeType) {
    if (changeType === undefined) {
        console.log('Song list has been rearranged');
    }
})
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
marceros
Posts: 25
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Thank you!

I think I need to do some homework.
Post Reply