PreviewWidget.add_attribute_value() doesn't accept array of objects
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
unity-js-scopes |
Fix Committed
|
High
|
Marcus Tomlinson |
Bug Description
I'm trying to use a PreviewWidget of type audio but have had no success so far.
The C++ API docs say that the 'tracks' attribute expects a composite attribute containing an array of tuples and that it can be created by using a VariantBuilder. However, for javascript, the VariantBuilder class does not seem to be present.
I have tried to use an array of objects, like this:
var audio = new scopes.
audio.add_
"tracks",
[
{
}
]
);
This fails with the following error:
file://
The PreviewWidget does get added and it includes a single track. The track does not show the title, and then when I try to click on the widget in order to hear the sound, I get this error:
file://
I've tried searching online for examples of this type, but came up short. Thanks for your help.
Related branches
- Alexandre Abreu (community): Approve
- PS Jenkins bot (community): Approve (continuous-integration)
-
Diff: 120 lines (+45/-14)4 files modifiedsrc/bindings/src/common.cc (+21/-13)
src/bindings/src/preview-widget.cc (+18/-1)
src/bindings/src/variant.cc (+4/-0)
src/bindings/src/variant.h (+2/-0)
Changed in unity-js-scopes: | |
assignee: | nobody → Marcus Tomlinson (marcustomlinson) |
status: | New → Confirmed |
Changed in unity-js-scopes: | |
status: | Confirmed → In Progress |
importance: | Undecided → High |
summary: |
- PreviewWidget.add_attribute_value doesn't accept array of objects + PreviewWidget.add_attribute_value() doesn't accept array of objects |
Changed in unity-js-scopes: | |
status: | In Progress → Fix Committed |
I eventually got it working.
I had to pass a an object as the second argument to the add_attribute_ value() method. Like this:
audio.add_ attribute_ value(
"title" : result. get("title" ),
"source" : result. get("audio_ preview_ url")
"tracks",
{
}
);
This works and the widget is able to show the title and playback the audio. However, it does not allow adding multiple tracks to the widget because only the last pair is recognized.
I guess that in order to comply with the docs, the PreviewWidget's add_attribute_value method of the bindings should be checking for a variant of type array (line #89 of preview-widget.cc) and handle it instead of checking for a dict, as it currently stands.