Dev for external HTML now playing view
Moderators: jiri, drakinite, Addon Administrators
Dev for external HTML now playing view
-
Last edited by boopedoo on Fri Jan 17, 2025 6:14 pm, edited 1 time in total.
Dev for external HTML now playing view
Hey there. Been banging my head on this for a week or so.
I've tried several implementation approaches to get a simple local html file to display albumart and title-artist as "now playing" so I can use it in other applications.
So far, outputting to JSON has failed, as has outputting to HTML, and just outputting to .txt using a preexisting addon and then converting to HTML.
This is currently failing:
I am attempting to recreate something like a spotify widget.
I have also looked into installing MMremote5 and faking an android connection to get the data that way.
Any help or pointers in the right direction would be appreciated.
I've tried several implementation approaches to get a simple local html file to display albumart and title-artist as "now playing" so I can use it in other applications.
So far, outputting to JSON has failed, as has outputting to HTML, and just outputting to .txt using a preexisting addon and then converting to HTML.
This is currently failing:
Code: Select all
"use strict";
// Function to write the current track information to a JSON file
function write Now Playing ToJSON() {
const track = app.player. getCurrentTrack();
if (!track) {
console.log("No track is currently playing.");
return;
}
// Prepare track information
const trackInfo = {
artist: track. artist || "Unknown Artist",
title: track. name || "Unknown Title",
album: track. album || "Unknown Album",
artwork: track. artworkPath || "No Artwork Available"
};
const jsonContent = JSON. stringify(trackInfo, null, 2);
// Define the file path to save the JSON file
const filePath = "\\now_playing. json";
try {
// Save the JSON content to the file
app.filesystem.saveText ToFileAsync(filePath, jsonContent, function() {
console.log("Now Playing JSON saved to: " + filePath);
});
} catch (error) {
console.error("Error saving JSON file:", error);
}
}
// Listen for playback state changes and call writeNow PlayingToJSON when playback starts or is resumed
app.listen(app.player, 'playback State', function(newState) {
if (newState === 'play' || newState === 'unpause') {
writeNowPlayingToJSON();
}
});
I am attempting to recreate something like a spotify widget.
I have also looked into installing MMremote5 and faking an android connection to get the data that way.
Any help or pointers in the right direction would be appreciated.
Re: Dev for external HTML now playing view
Hi,
1) your code includes some unexpected spaces, e.g. instead of
use
i.e. the third param is optional, for the structure of the param see: https://www.mediamonkey.com/docs/api/cl ... oFileAsync
2) instead of track.artworkPath use track.getThumbAsync :
1) your code includes some unexpected spaces, e.g. instead of
Code: Select all
app.filesystem.saveText ToFileAsync(filePath, jsonContent, function() {
console.log("Now Playing JSON saved to: " + filePath);
});
Code: Select all
app.filesystem.saveTextToFileAsync(filePath, jsonContent, {});
2) instead of track.artworkPath use track.getThumbAsync :
Code: Select all
track.getThumbAsync(500 /* PX */, 500 /* PX */, function(thumbPath) {
let trackInfo = {
title: track.title,
artist: track.artist,
artworkPath: thumbPath
}
app.filesystem.saveTextToFileAsync( filePath, JSON.stringify( trackInfo));
});