Closed rafaucau closed 2 weeks ago
This is a serious issue, because autoplay will not work on ios without the muted attribute.
Workaround like this:
let ref!: HTMLVideoElement
onMount(() => {
ref.setAttribute("muted", `true`)
})
But still, a fix on this will be appreciated
That workaround fixed the issue for me, but would also appreciate this for iOS safari autoplay
Weirdly I have the same problem. On one page it just removes the muted from all videos... 😅 The workaround doesn't help either.
@eriksachse Try this sample workaround:
<div>
{@html '<video muted autoplay loop defaultmuted playsinline src="/animation.mp4" />'}
</div>
So you put the <video>
as an HTML string.
Another workaround (?), I don't have the issue if I've imported the file using Vite static imports: https://vitejs.dev/guide/assets.html#importing-asset-as-url
<script>
import hero_mp4 from '$lib/assets/marketing/landing/hero-gif.mp4';
const kedyou_mp4 = '/comparisons/kedyou.mp4';
</script>
<video autoplay playsinline loop muted>
<source src={hero_mp4} type="video/mp4" />
</video>
<video autoplay playsinline loop muted>
<source src={kedyou_mp4} type="video/mp4" />
</video>
Produces the output:
<video autoplay playsinline loop muted>
<source src="/_app/immutable/assets/hero-gif.631030a2.mp4" type="video/mp4">
</video>
<video autoplay playsinline loop> <!-- muted missing??? -->
<source src="/comparisons/kedyou.mp4" type="video/mp4">
</video>
Does it have something to do with this:
let videoElement = document.createElement('video')
//this will work
videoElement['controls'] = true;
videoElement['loop'] = true;
//this will NOT work
videoElement['muted'] = true;
document.body.appendChild(videoElement);
If so, than issue with browsers, when attributes are set as properties
Wow, this issue has been here for almost three years. Is it so hard to fix? :)
@stulnikov-roud - It's a spicy one, see same issue for react https://github.com/facebook/react/issues/10389
I believe https://github.com/sveltejs/svelte/pull/14095 should have fixed this.
@trueadm @Rich-Harris can this fix be made available in svelte 4 also, please?
Describe the bug
The muted attribute does not render in the video tag which prevents autoplay on Safari when using client side routing.
Info from @GrygrFlzr
Reproduction
muted
andautoplay
attributes. E.g.: https://svelte.dev/repl/9fb1ac3f9a314bd3947fb1c62cdb1dcfWhen using client side routing in SvelteKit, when navigating through pages, the video will not automatically play on Safari.
Logs
No response
System Info
Severity
annoyance