Blazored/Video

Autplay

michalss opened this issue · 3 comments

Hi is there some example how to do autoplay just after page is rendered in Blazor Server?

i did try
autoplay="autoplay"
loop="loop"

But is simply not start

You can try adding "muted" to the attributes, but even then it is not guaranteed to autoplay.
Browsers are in control of things like this and they can all handle it differently.

This seems to work:

index.html

    <script>
        function autoPlay(id)
        {
            document.getElementById(id).play();
        }
    </script>

index.razor

@inject IJSRuntime JS

<BlazoredVideo
            id="myId"
            muted="muted"
            autoplay="autoplay"
            LoadedData="LoadedData">
        <source src="@path" type="video/mp4" />
</BlazoredVideo>
    private void LoadedData(VideoState state)
    {
        JS.InvokeVoidAsync("autoPlay", "gource");
    }

Just make sure you interact with the page first (by clicking somewhere for example). Or else you get Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.