Sonos album Art Size in presentation map - sonos

Can someone explain how to configure the Sonos Presentation map to adjust ArtSize URI via the pmap. Our base URL is:
http://....../load_albumart.php?album_id=12&size=200
I do not understand how to configure the pmap to replace 200 in 600 for example.

The PresentationMap for Album Art works like a regular expression. When the controller wants an image that is 200x200, it will search the albumArtUri element and replace the string you configure as a size substitution.
In your case you have these URLs based on your example:
http://.../load_albumart.php?album_id=12&size=200
http://.../load_albumart.php?album_id=12&size=600
http://.../load_albumart.php?album_id=12&size=XXXX
Your presentation map will then identify the substitution rules for each resolution. In your case, something like:
<PresentationMap type="ArtWorkSizeMap">
<Match>
<imageSizeMap>
<sizeEntry size="200" substitution="size=200"/>
<sizeEntry size="600" substitution="size=600"/>
<sizeEntry size="XXXX" substitution="size=XXXX"/>
</imageSizeMap>
</Match>
</PresentationMap>
And your default SMAPI response that contains an albumArtUri would include a default size like so:
<trackMetadata>
<albumId>12</albumId>
<duration>253</duration>
<artistId>artist0001</artistId>
<artist>Saratoga Indiana</artist>
<album>Forgiveness & Gratefulness</album>
<albumArtUri>http://.../load_albumart.php?album_id=12&size=200</albumArtUri>
</trackMetadata>
In this scenario, if the controller has a hi-resolution display (E.g. Retina or xhdpi), the controller will then use the presentation map to load the highest resolution image that makes sense by replacing the substitution from the resolution the controller wants (identified by the size attribbute in a sizeEntry node) with the resolution the trackMetadata (or mediaMetadata) has in the albumArtUri node.
There is a short tutorial available on the Sonos developer website that has more details.
Also, while I realize you are probably using 200 and 600 as example resolutions, please note Sonos asks for a specific set of resolutions (sizeEntry elements with specific size attributes) that work best on the various controller platforms. Those resolutions are described in the tutorial.
Although you may not offer all resolutions in Sonos' preferred list, the controller will take the next largest size in the configuration. E.g. Sonos asks for a 180x180 image. In this example, the controller would select the 200 pixel configuration as the next highest resolution above 180. For 300x300 and 600x600, the controller would use the size="600" sizeEntry.

Related

In gym, how should we implement the environment's render method so that Monitor's produced videos are not black?

How are we supposed to implement the environment's render method in gym, so that Monitor's produced videos are not black (as they appear to me right now)? Or, alternatively, in which circumstances would those videos be black?
To give more context, I was trying to use the gym's wrapper Monitor. This wrapper writes (every once in a while, how often exactly?) to a folder some .json files and an .mp4 file, which I suppose represents the trajectory followed by the agent (which trajectory exactly?). How is this .mp4 file generated? I suppose it's generated from what is returned by the render method. In my specific case, I am using a simple custom environment (i.e. a very simple grid world/maze), where I return a NumPy array that represents my environment's current state (or observation). However, the produced .mp4 files are black, while the array clearly is not black (because I am also printing it with matplotlib's imshow). So, maybe Monitor doesn't produce those videos from the render method's return value. So, how exactly does Monitor produce those videos?
(In general, how should we implement render, so that we can produce nice animations of our environments? Of course, the answer to this question depends also on the type of environment, but I would like to have some guidance)
This might not be an exhaustive answer, but here's how I did.
First I added rgb_array to the render.modes list in the metadata dictionary at the beginning of the class.
If you don't have such a thing, add the dictionary, like this:
class myEnv(gym.Env):
""" blah blah blah """
metadata = {'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': 2 }
...
You can change the desired framerate of course, I don't know if every framerate will work though.
Then I changed my render method. According to the input parameter mode, if it is rgb_array it returns a three dimensional numpy array, that is just a 'numpyed' PIL.Image() (np.asarray(im), with im being a PIL.Image()).
If mode is human, just print the image or do something to show your environment in the way you like it.
As an example, my code is
def render(self, mode='human', close=False):
# Render the environment to the screen
im = <obtain image from env>
if mode == 'human':
plt.imshow(np.asarray(im))
plt.axis('off')
elif mode == 'rgb_array':
return np.asarray(im)
So basically return an rgb matrix.
Looking at the gym source code, it seems there are other ways that work, but I'm not an expert in video rendering so for those other way I can't help.
Regarding your question "how often exactly [are the videos saved]?", I can point you to this link that helped me for that.
As a final side note, video saving with a gym Monitor wrapper does not work for a mis-indentation (as of today 30/12/20, gym version 0.18.0), if you want to solve it do like this guy did.
(I'm sorry if my English sometimes felt weird, feel free to harshly correct me)

How to programmatically get images commonly used in Eclipse Plug-ins

What are the places to look for if a plug-in wishes to re-use images that are defined by other plug-ins.
For example, where to look for if a plug-in needed the 'Terminate' icon, defined somewhere in the debug plug-in.
Now and then I have been searching for images and though it would be useful to list the locations of commonly used images in one place.
Some of the platform plug-ins make (some of) their images available though ImageDescriptors. Unfortunately all in a slightly different way.
Platform UI - org.eclipse.ui
This plug-in defines images for public use in ISharedImages. To obtain an image descriptor, query the workbench's image registry like this:
PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJ_FILE );
IDE - org.eclipse.ui.ide
The IDE plug-in adds some more images to the workbench image registry and lists the registered names in IDE.ISharedImages.
To obtain an image descriptor, also query the workbench's image registry like this:
PlatformUI.getWorkbench().getSharedImages().getImage( IDE.ISharedImages.IMG_OBJ_PROJECT );
Debug - org.eclipse.ui.debug
The debug plug-in defines shared images in IDebugUIConstants, image name constants start with IMG_. They can be access through the DebugUITools utility class.
For example:
DebugUITools.getImageDescriptor( IDebugUIConstants.IMG_ACT_RUN );
Compare - org.eclipse.compare
The compare plug-in defines ImageDescritpors for Next and Previous images directly in CompareUI.
For example:
ImageDescriptor next = CompareUI.DESC_DTOOL_NEXT;
Team - org.eclipse.team.ui
The team plug-in as well uses a ISharedImage interface to declare overlay images to decorate modified, conflicting, etc. resources.
The image descriptors can be obtained through the TeamImages class:
ImageDescriptor imageDescriptor = TeamImages.getImageDescriptor( ISharedImages.IMG_DIRTY_OVR );
JDT - org.eclipse.jdt.ui
JDT aligns with the workbench when providing images. Its ISharedImages interface defines the registered names and JavaUI.getSharedImages() allows to obtain the respective image descrptors.
Directly Accessing Images
AbstractUIPlugin has a static helper method to get a descriptor of an image in an arbitrary plug-in.
ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( "the.bundle.id", "/icons/sample-image.png" );
Warning: Loading images in this way is risky and should generally be avoided. Image locations are not part of a plug-ins API and a plug-in author may choose to delete or move the image which will break your code. If you need proof that this actually happens, have a look at this post.
If you need an image from a plug-in that doesn't make it available through its API, you should prefer to place a copy of that image within your plug-in.

Is it possible to tell a Windows 8.1 app not to scale up specific elements?

I am referencing external image urls for the source property of an image element in my app.
I have 3 versions of the image at 100, 140 and 180 scales e.g.
myimage.scale-100.jpg
myimage.scale-140.jpg
myimage.scale-180.jpg
If the images lived in the app you would normally put the source like the following and Windows works out which image to load based on the resolution scale of the device:
ms-appx:///Assets/Images/myimage.jpg
However as my 3 images live externally I am having to work out the resolution scale and then build up the correct source string so that the correct image is loaded e.g:
http://www.mywebsite.com/myimage.scale-180.jpg
This works, however, windows is taking my image e.g. the 180 scale one myimage.scale-180.jpg, and then scaling it up by a further 180%, it doesn't know that I have loaded an image at the correct 180% scale already and that it doesn't need to scale it up!
Is there a way of telling it not to scale up specific image elements?
Update (added code):
The xaml image element:
<Image Source="{Binding Image, Converter={StaticResource ImageToExternalImagePathConverter}}" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="None" />
The converter used on the image element to determine the external image path (it works out the scale and uses the binding to build up the correct string).
public object Convert(object value, Type targetType, object parameter, string language)
{
ResolutionScale resolutionScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().ResolutionScale;
string ImageScale = ".scale-100";
switch (resolutionScale)
{
case ResolutionScale.Scale140Percent:
ImageScale = ".scale-140";
break;
case ResolutionScale.Scale180Percent:
ImageScale = ".scale-180";
break;
}
//builds up the correct string e.g. http://www.mywebsite.com/myimage.scale-180.jpg
string externalPath = "http://www.mywebsite.com/" + (string)value + ImageScale + ".jpg";
return externalPath;
}
Update(added reference):
To further explain what I am currently doing see this link:
http://msdn.microsoft.com/en-us/library/windows/apps/hh465362.aspx
Manually load images based upon scale percentage at runtime If your
app is loading images at runtime using code, for example if you use
DirectX directly, not XAML or HTML to create your UI, use the
DisplayProperties.ResolutionScale property to determine the scale and
manually load images based upon scale percentage.
So that's what I am doing, but the problem is that Windows is scaling up the UI as it should to 140% or 180%, and that includes my manually loaded image. So if I manually load in an image that is already sized at 140%, it gets scaled up by Windows anyway and it DOES get physically bigger. If the images lived in the app package this problem wouldnt exist because Windows recognises the filename identifiers and doesnt scale them up (see below)
Use resource loading for bitmap images in the app package For bitmap
images stored in the app package, provide a separate image for each
scaling factor(100%, 140%, and 180%), and name your image files using
the "scale" naming convention described below. Windows loads the right
image for the current scale automatically.
How can I replicate the same behavior from Windows for images that live in the app package but for images that are external to the app and are loaded manually? Logically at the point at which I load the image in (code), I want to say to Windows, this image is already scaled correctly, don't upscale it by the resolution factor.
Try sizing grip property to false

Set windows size of QuickLook Plugin

I'm building a QuickLook plugin. I want to change the width of the windows that pops up when user hits the spacebar.
I've read there are two keys in the info.plist file of the project where height and width are customisable. Even if I change those values I can't get the size of the preview windows to my desired one.
I don't know what else to try. Any idea?
Thanks!
Thought I'd dig a little on this. I have not tried any of the following suggestions, so nobody get their hopes up. I'll assume you're using the generator callback:
OSStatus (*GeneratePreviewForURL)(
void *thisInterface,
QLPreviewRequestRef preview,
CFURLRef url,
CFStringRef contentTypeUTI,
CFDictionaryRef options
);
Before anything else, you might manually check the options dictionary argument and verify that the kQLPreviewPropertyWidthKey and kQLPreviewPropertyHeightKey keys are indeed mapped to the desired CFNumber values.
Referring to each of these properties, the Apple QuickLook programming guide says:
Note that this property is a hint; Quick Look might set the width
automatically for some types of previews. The value must be
encapsulated in a CFNumber object.
(Edit: If your preview representation is flexible, you might try finding a preview type for which QuickLook honors your size hints, as per the statement above. Just a thought.)
Running nm on the QuickLook framework binary revealed some undocumented kQLPreviewProperty-- constants as well as the aforementioned width and height keys. One that caught my attention was kQLPreviewPropertyAutoSizeKey. Recalling Apple's statement about ignoring the hints to set the size automatically, this might be significant? Following the convention in QuickLook.framework/Headers/QLBase.h, you might try declaring
extern const CFStringRef kQLPreviewPropertyAutoSizeKey;
Then you could try associating a CFNumber 0 with that property key in the options dictionary. There are other undocumented keys of note, such as kQLPreviewPropertyAttributesKey.
Back to the Info.plist you mentioned, Apple says about those keys QLPreviewWidth and QLPreviewHeight:
This number gives Quick Look a hint for the width (in points) of
previews. It uses these values if the generator takes too long to
produce the preview. (emphasis added)
This is where someone makes the terrible suggestion of calling sleep() in your generator. But I'm perplexed as to why Apple would make following the size hints dependent on the generator latency. (?)
Edit: Also note the above statement says the Info.plist hints must be expressed in points (not pixels), a unit dependent on the user's screen resolution.
Recently I was developing a Quick Look Plugin myself which uses HTML+CSS and faced the same problem.
The solution for my was to test the plugin not within Xcode and qlmanage as the executable but instead to try the real .qlgenerator from my user library.
When invoking the generator from my user library, the Quick Look window was resized exactly the way I specified in the *-Info.plist.
I've run into the same problem, and may offer some clues: In my case I'm generating an image quick look preview for my custom file format. I initiate the preview context to draw my preview into using
CGContextRef QLPreviewRequestCreateContext(QLPreviewRequestRef preview, CGSize size, Boolean isBitmap, CFDictionaryRef properties);
The curious thing is that if I set isBitmap to true, quick look adjusts the preview panel size to the size specified for the context (up to a certain size at least). But if you set isBitmap to false, it seems to disregard the context size and instead always shows a full size preview panel with the vector graphics image scaled to cover the entire panel.
So, if you use a bitmap graphical preview context, it seems the preview panel will be set to the size of the context you specify. However, I haven't found any way to set the size of the panel when using a vector graphic preview context (which is what I want).

Putting in "broken image" placeholders with Flying Saucer

I'm using Flying Saucer to generate PDF from HTML (so I'm using ITextRenderer, if that matters.)
I would like to simulate something like what Webkit or Gecko put in when the image cannot be found - something like an inset outline and a little broken page image.
I have determined that overriding getImageResource in the UserAgentCallback is a way to test for this condition (the image in the ImageResource will be null) but I can't figure out a nice way to render a placeholder at this point in the API.
Is there a proper way to do this? (It would be nice if this happened out of the box...)
You're on the right track here.
You want to extend UserAgentCallback with your own custom user agent functionality. It should perform almost the identical functionality of what the existing Flying Saucer implementation does, except, when an image is not found, it should return the default broken page image that you want to include.
If you're using the iTextRenderer, there is an ITextUserAgent class which you can extend for your own custom UserAgent.
To set the UserAgent, after you create the ITextRenderer, use the following code.
ITextRenderer renderer = new ITextRenderer();
renderer.getSharedContext().setUserAgentCallback(new CustomITextUserAgent(renderer.getOutputDevice()));