Enabling package to use playlist from assets

Hi there Florian!

I’m hoping for a quickstart guide on how I can give my node.lua file access to a playlist of assets i’ve created in the assets tab.

I understand i have to setup options in the node.json file, and somehow i’ll then be able to reference the playlist and the assets within it within the node.lua program… but i’m a bit stuck on the syntax of what i need to add to the node.json file. Any help and/or code examples would be much appreciated.

Thanks!

Tim

First you need a list of items in node.json like this:

{
    "title": "Playlist",
    "name": "playlist",
    "type": "list",
    "itemname": "Item",
    "items": [{
        "title": "Asset",
        "ui_width": 8,
        "name": "asset",
        "type": "resource",
        "valid": ["image", "video"],
        "default": "empty.png"
    }, {
        "title": "Play time (in seconds)",
        "ui_width": 4,
        "name": "duration",
        "type": "duration",
        "default": 10
    }]
}

The name of the playlist ("playlist" in this example) is up to you, but is later used in the generated config.json on the device. The "items" value needs some special requirements to make such a list “playlist-compatible”. Namely one entry called "asset" and one named "duration". If both of those are included as properties of a list’s item description, the configuration UI on the dashboard will allow you to easily use assets or native playlists when filling that playlist.

If you create a setup based on such a package, the config.json file generated and synced to the device now contains the configured assets like this:

  ... 
  "playlist": [
    {
      "duration": 10,
      "asset": {
        "asset_id": 12345,
        "asset_name": "asset-d8e8fca2dc0f896fd7cb4cb0031ba249-asset-filename.jpg",
        "filename": "asset-filename.jpg",
        "metadata": {
          "format": "jpeg",
          "height": 1080,
          "width": 1920
        },
        "tags": [],
        "type": "image"
      }
    }, [... possibly more assets...]
  ],
  ...

Once the config.json file is updated (you can detect that with util.json_watch), you are guaranteed that the asset files referenced by "asset_name" are also already available for use on the device.

Hope that help.