Just a small exercise for myself, but thinking 100% of my problem is me forgetting how JS works (it's been a while) and not knowing too much about HTML5. Anyways, I'm writing a short script to spit out the song and artist to a file when the song playing changes. I'm sure there's already something like that out there, but wanted to try it out for myself as an exercise. I think I've got the what from the API and the .js scripts, but the how is alluding me. The bare bones idea is:
Code: Select all
window.whenReady(() => {
var plyr = document.querySelector("[data-id='player']"); // Grab the player element
plyr.addEventListener('nowPlayingModified', displayTrack); // Add a listener to the element for when the track changes
function displayTrack() { // Get the information on the currently playing track
var track = app.player.getCurrentTrack();
uitools.toastMessage.show(track."whatever the title property is", {
disableUndo: true
}); // Will be replaced with the export command later once I get this working
}
});
My understanding is that
-app.player is the player object of class Player,
-the HTML element is labeled as data-id=player
-the event defined in the Player class that I want to listen for is nowPlayingModified
-Player.getCurrentTrack will get me the current track that is playing
Currently have the toast message just programmed to pop up as "Track Changed" to get the event listening down, but have not even got that working yet. So clearly I'm not listening to the event properly. Any thoughts?
Just a small exercise for myself, but thinking 100% of my problem is me forgetting how JS works (it's been a while) and not knowing too much about HTML5. Anyways, I'm writing a short script to spit out the song and artist to a file when the song playing changes. I'm sure there's already something like that out there, but wanted to try it out for myself as an exercise. I think I've got the what from the API and the .js scripts, but the how is alluding me. The bare bones idea is:
[code]window.whenReady(() => {
var plyr = document.querySelector("[data-id='player']"); // Grab the player element
plyr.addEventListener('nowPlayingModified', displayTrack); // Add a listener to the element for when the track changes
function displayTrack() { // Get the information on the currently playing track
var track = app.player.getCurrentTrack();
uitools.toastMessage.show(track."whatever the title property is", {
disableUndo: true
}); // Will be replaced with the export command later once I get this working
}
});[/code]
My understanding is that
-app.player is the player object of class Player,
-the HTML element is labeled as data-id=player
-the event defined in the Player class that I want to listen for is nowPlayingModified
-Player.getCurrentTrack will get me the current track that is playing
Currently have the toast message just programmed to pop up as "Track Changed" to get the event listening down, but have not even got that working yet. So clearly I'm not listening to the event properly. Any thoughts?