One player at a time across the tabs of an app, through Web Locks.
On a desktop, no engine stops the audio of one tab when another tab starts, so two tabs of a podcast app play at once and race to save the position. attach! holds a lock named for the app while the element plays, and takes it from any other tab that holds it, which then pauses its own element:
(def detach!
(attach! audio "my-podcast-app"))
The functions take these opts:
One player at a time across the tabs of an app, through Web Locks.
On a desktop, no engine stops the audio of one tab when another tab
starts, so two tabs of a podcast app play at once and race to save the
position. attach! holds a lock named for the app while the element
plays, and takes it from any other tab that holds it, which then pauses
its own element:
(def detach!
(attach! audio "my-podcast-app"))
The functions take these opts:
- :window, the window whose navigator holds the locks, instead of the
page's, e.g. a stand-in in a test(attach! element name)(attach! element name opts)Hold the Web Lock of name while the media element plays, with the
opts above, and pause the element when another tab takes the lock.
Return a function that detaches it.
The element takes the lock from any holder when it plays, and lets it go when it pauses and at pagehide, since a held lock keeps a page out of the back/forward cache. Where the browser has no Web Locks, the call does nothing.
Hold the Web Lock of `name` while the media `element` plays, with the `opts` above, and pause the element when another tab takes the lock. Return a function that detaches it. The element takes the lock from any holder when it plays, and lets it go when it pauses and at pagehide, since a held lock keeps a page out of the back/forward cache. Where the browser has no Web Locks, the call does nothing.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |