Sending Player info to a window

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

Moderators: jiri, drakinite, Addon Administrators

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

Sending Player info to a window

Post by marceros »

Hello,

I have a plug-in written in Visual Studio, C# for MM4 - it's been woring for many years now - that I'm trying to move to MM5. The plug-in gets info from the Player and writes it into Text controls in a Windows Form.

In MM5 I'm using the App.Player events, methods and properties to get the info from the Player and I managed to send it to the console.log and to a ToastMessage as in the following code:

Code: Select all

function displayTrack(event) {
	if(event == 'trackChanged'){
		var track = app.player.getCurrentTrack();
		var nextTrack = app.player.getNextTrack();
		var title = track.title;
		var nextTitle = nextTrack.title;
		uitools.toastMessage.show(track.title, {
				disableUndo: true
		});
		console.log(title);
		console.log(nextTitle);
	};
}

app.listen(app.player,'playbackState', displayTrack);
Now I have to create an external window - non-modal - and show the info dynamically and I'm not sure how to deal with that. I'd appreciate some guidelines and, if possible, examples.

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

Re: Sending Player info to a window

Post by drakinite »

To create your own custom window, you'll need to put the files in the dialogs folder. For an example, check the caseChecker script included with MM.

It includes the files dlgCaseChecker.html and dlgCaseChecker.js, and to instantiate the window, it uses uitools.openDialog(): https://www.mediamonkey.com/docs/api/cl ... openDialog - To make it a non-modal window, simply provide modal: false inside params.

Check actions_add.js line 9. It passes the tracklist to dlgCaseChecker.js as the variable named tracks, inside of the params provided to uitools.openDialog().

Inside the init function in dlgCaseChecker.js (line 252), it retrieves the tracklist from params.tracks.

There are plenty of other examples to view in the main MM code, as well, if you do a search for uitools.openDialog and/or peruse the dialogs folder.

Edit: After re-reading your original message, I see now that you were talking about Windows Forms. If you're looking to instantiate the Windows Forms window from JS code, I believe that would be more difficult. LMK if that's actually what you were trying to do.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Thank you so much for the response. In the next days I'll continue working on this project and use the info in your answer.

Marcelo
marlynne
Posts: 1
Joined: Thu Jun 09, 2022 3:50 am

Re: Sending Player info to a window

Post by marlynne »

Thx for the information I will use it for myself as well :)
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

marceros wrote: Thu May 26, 2022 12:01 pm Thank you so much for the response. In the next days I'll continue working on this project and use the info in your answer.

Marcelo
I could create/open a second window from a new menu that I created and I'm displaying there information about the track that's playing at every moment.

Now I need to get info about several tracks before the one that is playing and several tracks after the one that is playing. I assume that using the "playlistPos" property in conjunction with the "getSongList" method will do the job. I can get and use the "playlistPos" but cannot find a way to use the "getSongList" so I get info about the tracks around the playing track. I guess I should loop forward and backward from the playing track.

I'd appreciate getting some examples of the use of the "getSongList" method or an explanation about about to do those loops.

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

Re: Sending Player info to a window

Post by drakinite »

I realize now that PlaylistEntries (the object type returned by app.player.getSongList()) isn't documented. It shares nearly every method with Tracklist, but you can "transform" it into a regular tracklist with the method getTracklist().

I'm not sure if this is the best way of doing it, but you can get the currently playing track's index by first doing app.player.getCurrentTrack() and then doing list.indexOf(track). Here's a sample:

Code: Select all

let tracklist = app.player.getSongList().getTracklist();
await tracklist.whenLoaded();

let trackObj; // Single variable reference for faster memory access

trackObj = app.player.getCurrentTrack(); // doesn't have to be inside the list's read lock

// to use indexOf, getValue, and getFastObject, you need to enter a read lock
tracklist.locked(() => {
    // Get the index of the current track
    let selIndex = tracklist.indexOf(trackObj);
    // you'll want to do something smarter than this, to avoid indexes < 0 or > length, but this is just to demonstrate the concept
    for (let offset = -2; offset <= 2; offset++) {
        let thisIndex = selIndex + offset;
        // Get the track data
        trackObj = tracklist.getFastObject(thisIndex, trackObj);
        // Do stuff with the track data
        console.log(trackObj.summary)
    }
})
Side note 1: For an explanation on why you need to do locked(), read the blurb at the top of this page: https://www.mediamonkey.com/docs/api/cl ... dList.html
Side note 2: For an explanation on what the deal is with getFastObject(), read this: https://www.mediamonkey.com/docs/api/cl ... FastObject - if this doesn't fit your use, change it to getValue().
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Thank you so much!!! This part of the program seem to work fine!

I didn't use indexOf because some of the songs are repeated in the player. Instead I used app.player.playlistPos

I wasn't sure about how to use the getFastObject method and the trackObj so I used getValue and it works

Thanks again,
Marcelo
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Hello!

The logics of the part of the program that checks the TrackList and replaces the texts in the HTML dialog work fine. I tried it with a simple HTML file (dlgDanceFloorDisplay.html)

Code: Select all

<html class="dialog">
<head>
    <title>Dance Floor Display</title>
    <script src="file:///mminit.js"></script>
    <script src="dlgDanceFloorDisplay.js"></script>
</head>
<body>
	<div id="Milonga" class="blablaclass" style="color:red"></div>
	<div id="DJ" class="blablaclass" style="color:red"></div>
	<div id="TandaOrchestra" class="blablaclass" style="color:red"></div>
	<div id="TandaVocals" class="blablaclass" style="color:red"></div>
	<div id="SongGenre" class="blablaclass" style="color:red">SongGenre</div>
	<div id="ArtistYear" class="blablaclass" style="color:red">ArtistYear</div>
</body>
</html>
and I used lines like the following

Code: Select all

gl_wnd.document.getElementById('SongGenre').innerHTML = currentTitle + ' (' + currentGenre + ')';
in the JS script to replace the texts

Since I need a display that is a bit more sophisticated - something with centered text boxes of different sizes, colors, etc. - I'm looking for a way to create a template graphically and then export their source so it can replace my simple dlgDanceFloorDisplay.html

My question is what's the best way to do that, since I don't have experience with HTML development and the options available.

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

Re: Sending Player info to a window

Post by drakinite »

If you're looking to preserve the visual style of MediaMonkey, I would say the best thing to do would be to copy an existing dialog box that's similar enough to what you're looking for, and tweak it from there. The way to get the best results would be to code it from scratch, though it's understandable if that'd be a bit overwhelming.

There are some visual HTML builders out there, though I haven't tried any. After doing a short search, I found two: BlueGriffon by Mozilla and HTML website builder by Nicepage. No idea how good either are, though; and it may make your dialog kinda "stick out" by using its own style instead of using an MM skin.

You could also try an online HTML+CSS editor (there are a ton out there, but here's one: https://html-css-js.com), and paste in the auto-generated CSS file from one of the MediaMonkey skins (%appdata%/MediaMonkey5/precompiledLess_<skinname>.css), to get an instant preview of how your code will look.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Thank you for your suggestions! After trying to use them, I got to the conclusion that I'll use just HTML with styles. I think that the margin option together with the option of changing font, color and size will do the job.

I have a new question now. After doing all the mmip packing and installation manually - and wasting tons of time in it - I decided to use the pack-mmip package. The packing works fine but when I add the -o option, it opens the mmip instead of installing it. Is it because I changed the default of mmip extension to 7-zip, so it opens it? Should I change the default to something else, something related to MM5?

Thanks!!!!
Marcelo
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

marceros wrote: Fri Jun 24, 2022 9:32 am Thank you for your suggestions! After trying to use them, I got to the conclusion that I'll use just HTML with styles. I think that the margin option together with the option of changing font, color and size will do the job.

I have a new question now. After doing all the mmip packing and installation manually - and wasting tons of time in it - I decided to use the pack-mmip package. The packing works fine but when I add the -o option, it opens the mmip instead of installing it. Is it because I changed the default of mmip extension to 7-zip, so it opens it? Should I change the default to something else, something related to MM5?

Thanks!!!!
Marcelo
I tried it and I think it worked. It opens MM5 and still asks a few questions but it apparently installed the package. :D

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

Re: Sending Player info to a window

Post by drakinite »

Great! :slight_smile:
And yes - The -o option will simply attempt to open the file with whatever software is set to default. I would recommend setting MM5 to open MMIPs by default.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Sending Player info to a window

Post by Peke »

Hi,
If you use right click -> Open With -> And use 7Zip then even if you revert to MM opening by default it will still be in Open With Menu, so you will be able to extract MMIP if needed.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

drakinite wrote: Fri Jun 24, 2022 3:02 pm Great! :slight_smile:
And yes - The -o option will simply attempt to open the file with whatever software is set to default. I would recommend setting MM5 to open MMIPs by default.
I did. Thank you!
marceros
Posts: 36
Joined: Sun Apr 21, 2013 1:54 am

Re: Sending Player info to a window

Post by marceros »

Peke wrote: Fri Jun 24, 2022 3:08 pm Hi,
If you use right click -> Open With -> And use 7Zip then even if you revert to MM opening by default it will still be in Open With Menu, so you will be able to extract MMIP if needed.
Right! Thank you!
Post Reply