I have a javascript that lists a playlist of tracks and includes all of the player functions. I want to dynamically generate the playlist in JSON format by using a php call. I understand it is bad practice to try and 'include' php inside a js. So the basic set up is:
JAVASCRIPT START (first part) + PHP DYNAMICALLY GENERATED JSON LIST + JAVASCRIPT START (first part)Here is the section pulled out of the entire script:
// This is just a snippet but isolates the area of discussion
formatTime: function(secs) {
var minutes = Math.floor(secs / 60) || 0;
var seconds = (secs - minutes * 60) || 0;
return minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
}
};
// -START INCLUDE - I want to replace THIS section out with a dynamically generated list from PHP formatted in the same json format
var player = new Player([
{
title: 'Between Water and Flame',
file: 'Between-Water-and-Flame',
howl: null
},
{
title: 'Blossom',
file: 'Blossom',
howl: null
}
]);
// -END INCLUDE-
// Bind our player controls.
playBtn.addEventListener('click', function() {
player.play();
});
pauseBtn.addEventListener('click', function() {
player.pause();
});