Blazored / Video

The easiest html5 video implementation for Blazor applications
https://blazored.github.io/Video
MIT License
124 stars 28 forks source link

Autplay #12

Closed michalss closed 1 year ago

michalss commented 2 years ago

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

michalss commented 2 years ago

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

But is simply not start

SQL-MisterMagoo commented 2 years ago

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.

pieteckhart commented 2 years ago

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.