tvostvml

Access Asset Catalog images in TVML


I there any way to access images in contained within a local Asset Catalog from within TVML on the AppleTV?

I notice several of the templates in this example from Apple call out to resource:// URLs, which are common use images (more info on the dev forms). Here's an example button that gets rendered with the cloud symbol:

<buttonLockup>
  <badge src="resource://button-cloud" class="whiteBadge" />
  <title>Title 3</title>
</buttonLockup>

TVML Cloud Button

I tried pointing to some of my own resources instead of button-cloud but didn't have any success.

I have been able to change the icon on these buttons by linking to an externally served image like so:

<buttonLockup>
  <badge src="http://localhost:5000/static/heartFull.png" class="whiteBadge" width="50" height="50"/>
  <title>Title 3</title>
</buttonLockup>

Since these buttons will be re-used throughout my app, I'd rather load them locally than repeatedly calling them over HTTP if possible.


Solution

  • I had some success linking directly to the filesystem

    <badge src=\"file:///<url to bundle>/<relative path to resource>/<icon>.png\" width=\"50\" height=\"50\" />
    

    with... url to bundle from NSBundle.mainBundle().bundleURL.absoluteString, relative path according to your setup, eg. resources, images, ... and icon well, your image to show on the badge.

    Pulling from Assets.xcassets hasn't worked out so far, but then I am still in training. :-D