videojs / videojs-playlist

Playlist plugin for videojs
Other
368 stars 124 forks source link

How can I pass arguments from an external JSON file into the playlist sources? #104

Open coingenexchange opened 6 years ago

coingenexchange commented 6 years ago

So I have the following code in my videojs project:

 player.playlist([{
      name: 'Video 1',
      description: 'Video 1',
      sources: [{
        src: 'https://www.youtube.com/watch?v=k1D0_wFlXgo',
        type: 'video/mp4'
      }]
    },
    {
      name: 'Video 2',
      description: 'Video 2',
      sources: [{
        src: 'https://www.youtube.com/watch?v=9kRgVxULbag',
        type: 'video/mp4'
      }]
    }
  ]);

I also have a feed which will be populated with several video sources from an external API:

{
  "initial_slide": {
      "videos": [{
          "src": "https://www.youtube.com/watch?v=k1D0_wFlXgo"
      }, {
          "src": "https://www.youtube.com/watch?v=9kRgVxULbag"
      }, {
          "src": "xxxxx"
      }, { ....... (several more here) }
]
  }
}

I want to discover how I can populate the player.playlist.sources.src with the arguments from the external json feed. Is there a good way to do this?

Thanks in advance

saeidee commented 6 years ago

Just loop through the json and add one by one object in it ! `

    let resources = []
    for (const video of videos) {
        let resource = {
          sources: [{
            src: video.src,
            type: 'video/mp4'
          }],
          poster: ''
        }
        resources.push(resource)
    }
    player.playlist(resources)

`