Sending Player info to a window

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

Moderators: jiri, drakinite, Addon Administrators

marceros
Posts: 27
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: 849
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: 27
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: 4658
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: 27
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: 849
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: 27
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: 849
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: 27
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.
marceros
Posts: 27
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

I figured out how to use the 'change' event on the 'getSongList' method. I'm using the events with the parameter 'delete' and with no parameter and everything works fine besides the fact that it triggers the event several unnecessary times. I assume the triggers will be more accurate when the

But meanwhile, I found another strange behavior with the app.player.playListPos.

Let's say I have 10 songs in the player and the fifth song (playListPos=6) is now playing. Then, I move the sixth song to the place before the playing song so the moved song got the fifth place in the list and the playing song got the sixth place. The playListPos now should show 7 but it still shows 6.

Then I realized that I was reading the playListPos outside the tracklist locked function. Once I moved it into the function, it started working good.

Thank you!
marceros
Posts: 27
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Hello!

My program looks stable and does the main logics of the job. Before I write the next question/problem, I'd like to explain in a line or two what the program does.

I added a menu in the MM5 main window that opens a second window. Following is the code in the actions_add.js

Code: Select all

actions.openDanceFloorDisplay = {
    title: _('Dance floor display') + '...',
    hotkeyAble: true,
    // icon: 'openDanceFloorDisplay',
    // disabled: uitools.notMediaListSelected,
    visible: window.uitools.getCanEdit,
    execute: async function () {
        var dlg = uitools.openDialog('dlgDanceFloorDisplay', {
			left: 100,
			top: 100,
			width: 500,
			height: 500,
            show: true,
            modal: false,
            title: _('Dance floor display'),
            // tracks: list
        });
    }
}
That window goes to a second screen and displays information (to the people in the dance floor) about the theme that is playing and the following themes. All the logic is done in the JS of the open dialog and that's the part that I'm happy with.

Now I need to control the dialog from outside - from the main MM menu. Let's say that the second screen is different than expected and I have to change some internal parameters that control the text size and the height of the lines. Or I might want to change the text of the first line (title) showing on the second screen.

I guess the question is how I send data to the dialog JS (dlgDanceFloorDisplay.js) and how I run an update function in that JS, everything initiated from a menu in the main MM window.

Thank you in advance,
Marcelo
Post Reply