Blazored / Video

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

VideoState is Null on the "Play" event #3

Closed JPVenson closed 3 years ago

JPVenson commented 3 years ago

Describe the bug When attaching to the PlayCallback on an BlazoredVideo element, the VideoState is null

To Reproduce

<BlazoredVideo @ref="BlazoredVideo"
               controls="controls"
               Play="OnPlayerPlayed">
 <source src="https://res.cloudinary.com/blazoredgitter/video/upload/v1557015491/samples/elephants.mp4" type="video/mp4" />
</BlazoredVideo>
public void OnPlayerPlayed(VideoState obj)
{
    Console.WriteLine("State is " + (obj?.ToString() ?? "NULL"));
}

Is always null when i start of stop the video.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Hosting Model (is this issue happening with a certain hosting model?):

Additional context Add any other context about the problem here.

SQL-MisterMagoo commented 3 years ago

I cannot reproduce this issue - can you create a repo where I can see what is happening please? It may be related to whatever media source you are using, possibly - as that is the only thing not shown above in your example.

JPVenson commented 3 years ago

Sure: https://github.com/JPVenson/BlazoredBugNo3 Start the project, open your Browser debugger Console and you will see that the state is null

But i think i already found the problem. When attaching to an event without setting the VideoStateOptions will result in that behavior.

JPVenson commented 3 years ago

@SQL-MisterMagoo Added Source element

SQL-MisterMagoo commented 3 years ago

Ah yes, well spotted - you do need to provide VideoStateOptions - the default is to return nothing - because the choice for a default was either nothing, or all - and all seemed a bit messy as a default.

If you are not bothered about what is returned, then leaving it null should be fine - but if you do need something from the state, then you need to define what it is you are interested in.

JPVenson commented 3 years ago

"nothing" is ok, but not null. I expected the object to be at least created and empty but never null. It was just unexpected.

mithunta commented 3 years ago

HI, I am installed this package from nugget manager. I am working on simple blazor wasm application (.NET 5). To get the current times when user clicks on play and pause buttons. I am always getting VideoState as null on my OnPlay and OnPause events. My implementation is pretty simple as you can see below. I don't understand if there is something I am missing or doing wrong?

<BlazoredVideo  VideoStateOptions="options" Play="OnPlay" Pause="OnPause"
                class="w-100"
                style="width:1280px;"
                controls="controls" >
                <source src="https://res.cloudinary.com/blazoredgitter/video/upload/v1557015491/samples/elephants.mp4" type="video/mp4" />

             </BlazoredVideo>

<span>Current` Time: @currentTime</span>
@code{
public Dictionary<VideoEvents, VideoStateOptions> options {get; set; } 
private double currentTime;

    protected override void OnInitialized()
    {
        options = new Dictionary<VideoEvents, VideoStateOptions>();
        options[VideoEvents.TimeUpdate] = new VideoStateOptions { All=true };
        options[VideoEvents.Pause] = new VideoStateOptions {  All=true };
        options[VideoEvents.Play] = new VideoStateOptions {  All=true};
   }
   private void OnPlay(VideoState state)
    {
        collapseNavMenu = true;
        currentTime  = state.CurrentTime;

    }

    private void OnPause(VideoState state)
    {
        collapseNavMenu = false;
        currentTime = state.CurrentTime;

    }

}
JPVenson commented 3 years ago

@mithunta Try initializing the options inline:

public Dictionary<VideoEvents, VideoStateOptions> options {get; set; } = new Dictionary<VideoEvents, VideoStateOptions>();

Or use a componentBase class and put the initialization in your constructor.

mithunta commented 3 years ago

@JPVenson . Thank you for the suggestion. I tried both of your options. I still get VideoState as null during Play and Pause action i am doing. I have committed the code to Git repo - https://github.com/mithunta/blazoredvideo_net5

JPVenson commented 3 years ago

@mithunta You have a typo in your code: Its: VideoEventOptions not VideoStateOptions

mithunta commented 3 years ago

@JPVenson Darn it. Thank you!

@SQL-MisterMagoo - I think there is an error in the example code in Readme.md. This is where I took the implementation. image

mikocot commented 2 years ago

@JPVenson Darn it. Thank you!

@SQL-MisterMagoo - I think there is an error in the example code in Readme.md. This is where I took the implementation. image

Exactly, I have done the same, and just to be sure copy-pasted the exact code from the readme... :D This explains why VS didn't like that parameter