Video icon indicating copy to clipboard operation
Video copied to clipboard

Autplay

Open michalss opened this issue 2 years ago • 3 comments

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

michalss avatar Dec 31 '21 09:12 michalss

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

But is simply not start

michalss avatar Dec 31 '21 10:12 michalss

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.

SQL-MisterMagoo avatar Dec 31 '21 11:12 SQL-MisterMagoo

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.

pieteckhart avatar Jan 19 '22 20:01 pieteckhart