annals.media#

The media relay for published html pages: what a framed page plays, told to the page around it.

A spoken overview is an html page shown in a sandboxed frame, so the annals page cannot see its audio. This adds one inlined script (the page’s own ui/media-progress.js) to any html page that may play audio or video; the script posts what is played to the parent page, which records what the reader heard (annals.listening), and takes a “start at” from it. Opened on its own (no parent), the relay does nothing. Ahead of it goes the seek guard (ui/media-seek.js, also loaded by the annals page itself): on an iPhone, a seek on a paused element that has no data yet never lands and wedges every later seek, so the guard holds such a seek until the element plays or its data arrives.

Module Attributes

SEEK_JS

the seek guard, inlined first (shared pages too) so the relay's own seek and play go through it

Functions

add_media_relay(html, *[, relay])

html with the seek guard and the media relay injected, unless it plays nothing or opts out.

media_version()

A short hash of what add_media_relay() injects, for a page's ETag.

annals.media.SEEK_JS = PosixPath('/home/runner/work/annals/annals/annals/data/ui/media-seek.js')#

the seek guard, inlined first (shared pages too) so the relay’s own seek and play go through it

annals.media.add_media_relay(html, *, relay=True)[source]#

html with the seek guard and the media relay injected, unless it plays nothing or opts out. relay=False (a page nobody records, a share’s) injects the guard alone.

>>> add_media_relay(b"<p>no media</p>") == b"<p>no media</p>"
True
>>> page = add_media_relay(b"<body><audio src=a.mp3></audio></body>")
>>> b'data-annals-media="seek"' in page and b'data-annals-media="1"' in page
True
>>> shared = add_media_relay(b"<body><audio src=a.mp3></audio></body>", relay=False)
>>> b'data-annals-media="seek"' in shared and b'data-annals-media="1"' not in shared
True
>>> add_media_relay(b"<p>an audio overview</p>") == b"<p>an audio overview</p>"
True
Return type:

bytes

annals.media.media_version()[source]#

A short hash of what add_media_relay() injects, for a page’s ETag.

Return type:

str