(
{
album = '',
'aria-describedby': ariaDescribedby,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
artist = '',
artwork = '',
// TODO(dmanek): Use InOb hook for autoplay.
// autoplay = false,
controlsList,
loading = 'lazy',
loop = false,
muted = false,
onError,
onPause,
onPlaying,
preload,
sources,
src,
title = '',
...rest
},
ref
)
| 17 | * @return {PreactDef.Renderable} |
| 18 | */ |
| 19 | export function BentoAudioWithRef( |
| 20 | { |
| 21 | album = '', |
| 22 | 'aria-describedby': ariaDescribedby, |
| 23 | 'aria-label': ariaLabel, |
| 24 | 'aria-labelledby': ariaLabelledby, |
| 25 | artist = '', |
| 26 | artwork = '', |
| 27 | // TODO(dmanek): Use InOb hook for autoplay. |
| 28 | // autoplay = false, |
| 29 | controlsList, |
| 30 | loading = 'lazy', |
| 31 | loop = false, |
| 32 | muted = false, |
| 33 | onError, |
| 34 | onPause, |
| 35 | onPlaying, |
| 36 | preload, |
| 37 | sources, |
| 38 | src, |
| 39 | title = '', |
| 40 | ...rest |
| 41 | }, |
| 42 | ref |
| 43 | ) { |
| 44 | const audioRef = useRef(null); |
| 45 | const wrapperRef = useRef(null); |
| 46 | |
| 47 | /** @public {boolean} */ |
| 48 | const isPlaying = useRef(false); |
| 49 | |
| 50 | /** |
| 51 | * Prepares Media Metadata |
| 52 | */ |
| 53 | const metadata = useMemo( |
| 54 | () => ({ |
| 55 | title, |
| 56 | artist, |
| 57 | album, |
| 58 | artwork: [{src: artwork}], |
| 59 | }), |
| 60 | [title, artist, album, artwork] |
| 61 | ); |
| 62 | |
| 63 | /** |
| 64 | * Plays audio callback |
| 65 | */ |
| 66 | const play = useCallback(() => { |
| 67 | audioRef.current.play(); |
| 68 | isPlaying.current = true; |
| 69 | }, []); |
| 70 | |
| 71 | /** |
| 72 | * Pauses audio callback |
| 73 | */ |
| 74 | const pause = useCallback(() => { |
| 75 | audioRef.current.pause(); |
| 76 | isPlaying.current = false; |
nothing calls this directly
no test coverage detected