How to use a PreviewWidget of type audio?

Asked by ric silva

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.

Question information

Language:
English Edit question
Status:
Solved
For:
unity-js-scopes Edit question
Assignee:
No assignee Edit question
Solved by:
Marcus Tomlinson
Solved:
Last query:
Last reply:
Revision history for this message
Best Marcus Tomlinson (marcustomlinson) said :
#1

Hi ric, yeah, your code snippet looks right, and should work. Thanks for picking this issue up!

I've logged a bug from your observation here. I'll put together a fix for it today.

Once the fix lands, you should be able to run your code as you've put it above, without error.

Revision history for this message
ric silva (ricardo-garcia-silva) said :
#2

Thanks

I've updated the bug report with a bit more info. Nice to see it fixed so fast :)

Revision history for this message
ric silva (ricardo-garcia-silva) said :
#3

Thanks Marcus Tomlinson, that solved my question.

Revision history for this message
Alexandre Abreu (abreu-alexandre) said :
#4

The fix has been merged it should be available (released) in the next few days,