PreviewWidget.add_attribute_value() doesn't accept array of objects

Bug #1541720 reported by Marcus Tomlinson
8
This bug affects 1 person
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.lib.PreviewWidget("audio", "audio");
audio.add_attribute_value(
    "tracks",
    [
        {
            "title": new scopes.lib.Variant(result.get("title")),
            "source": new scopes.lib.Variant(result.get("audio_preview_url"))
        }
    ]
);

This fails with the following error:

file:///usr/share/unity8//Dash/Previews/PreviewAudioPlayback.qml:145:35: Unable to assign [undefined] to QString

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:///usr/share/unity8//Dash/Previews/PreviewAudioPlayback.qml:84: Error: Cannot assign [undefined] to QUrl

I've tried searching online for examples of this type, but came up short. Thanks for your help.

Related branches

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
Revision history for this message
ric silva (ricardo-garcia-silva) wrote :

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(
    "tracks",
    {
            "title": result.get("title"),
            "source": result.get("audio_preview_url")
    }
);

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.

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

You're right. There were a couple of other fixes to be made in order to support the

    "title": new scopes.lib.Variant(result.get("title")),

format as well.

Just pushed an MP.

Changed in unity-js-scopes:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.