0

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();
});
NetTemple
  • 319
  • 1
  • 13
  • I ONLY need the JS direction or syntax - I can generate the code in the proper format using a php call. So this is more of a concept question. – NetTemple Mar 04 '20 at 17:50
  • Probably easiest to use fetch https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch – Funk Doc Mar 04 '20 at 19:09

0 Answers0