question

Mohamed Sayed avatar image
Mohamed Sayed asked

How to Display APL along while AudioPlayer is running

I've created a python skill, that should play mp3 file and display on screen APL document with images and information about the mp3 currently running.

the problem is that once the AudioPlayer starts to run, the APL document disappears and is replaced by the "Now Playing" screen of the AudioPlayer


Here is my code


handler_input.response_builder.add_directive(
            PlayDirective(
                play_behavior=PlayBehavior.REPLACE_ALL,
                audio_item=AudioItem(
                    stream=Stream(
                        token=token,
                        url = get_sura_url(index,ayah_no,reciter_token),
                        offset_in_milliseconds=offset_in_ms,
                        expected_previous_token=None),
                    metadata=None
                        ))
                )

handler_input.response_builder.add_directive(
        RenderDocumentDirective(
            token=doc_token,
            document={
                "type": "Link",
                "src": f"doc://alexa/apl/documents/MY_DOC"
            },
            datasources=data_source
        )
    ) 


aplaudioplayerpython
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy Whitworth avatar image
Andy Whitworth answered

You can't use APL in an audio player based skill (when the tracks are playing). What you can do is include track metadata (track title, subtitle and images) in the AudioPlayer Play directive and these will display on the device for each track played. See the following reference doc for details of the metadata approach.

https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html#audioplayer-display

10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mohamed Sayed avatar image
Mohamed Sayed answered

I've done that and it is working, however, displaying metadata has a very limited and less flexibility to design the layout.

Text of title or subtitle is truncated.
You cannot customize where to position the items.
You cannot add images

1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Andy Whitworth avatar image Andy Whitworth commented ·

You can add a background image and a foreground image. But yes, the format is fixed.

That is all you can do with an Audio Player based skill, you cannot include APL documents. If you want to do that then you could look at using the Video APL component (which also plays MP3s) and will allow you to have greater control over the display items.

In summary, if you want to have control over the way images/text are presented when MP3 tracks are played then you cannot use the Audio Player interface and should look at the APL Video component instead.

1 Like 1 ·