frankhale / toby-blazor

A simple YouTube player written in C# / Blazor Server Side
MIT License
22 stars 1 forks source link

Close the plyer after finishing the video #11

Closed BogdanJak closed 5 months ago

BogdanJak commented 5 months ago

Hi How to automatically close the player window after the video ends?

Regards Bogdan

frankhale commented 5 months ago

Just added this. Also upgraded to .NET 8.

BogdanJak commented 5 months ago

I'm trying to create my own Youtube player example based on your code. But unfortunately I'm stuck. The link below is my Github repository. https://github.com/BogdanJak/ModalBlazorX Can you check what I'm doing wrong?

Regards Bogdan

frankhale commented 5 months ago

I will take a look.

On Sat, May 25, 2024 at 10:59 AM BogdanJak @.***> wrote:

I'm trying to create my own Youtube player example based on your code. But unfortunately I'm stuck. The link below is my Github repository. https://github.com/BogdanJak/ModalBlazorX Can you check what I'm doing wrong?

Regards Bogdan

— Reply to this email directly, view it on GitHub https://github.com/frankhale/toby-blazor/issues/11#issuecomment-2131302426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABONSROT77QD2JAE2GE4PDZECRLZAVCNFSM6AAAAABIGGSR2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZRGMYDENBSGY . You are receiving this because you modified the open/close state.Message ID: @.***>

frankhale commented 5 months ago

As a first step are you trying to create a component that plays a YouTube video? I see a bunch of issues with the current code which is why it does not work.

On Sat, May 25, 2024 at 11:51 AM Frank Hale @.***> wrote:

I will take a look.

On Sat, May 25, 2024 at 10:59 AM BogdanJak @.***> wrote:

I'm trying to create my own Youtube player example based on your code. But unfortunately I'm stuck. The link below is my Github repository. https://github.com/BogdanJak/ModalBlazorX Can you check what I'm doing wrong?

Regards Bogdan

— Reply to this email directly, view it on GitHub https://github.com/frankhale/toby-blazor/issues/11#issuecomment-2131302426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABONSROT77QD2JAE2GE4PDZECRLZAVCNFSM6AAAAABIGGSR2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZRGMYDENBSGY . You are receiving this because you modified the open/close state.Message ID: @.***>

BogdanJak commented 5 months ago

Beginnings are always difficult

frankhale commented 5 months ago

No worries. The important thing is that the YouTube API has to be initialized, this has to be done in JavaScript before a Blazor component can use it. Once the YouTube API is initialized and ready then a video can be played.

Start here, once you can get the example running then it should be fairly easy to get something working in Blazor:

https://developers.google.com/youtube/iframe_api_reference

That documentation has a complete and very simple working example of how to embed a YouTube video into a webpage. This is the core aspect of what I'm doing. The only difference between that simple example is that I'm adding a SQLite database and a few other features to save and search.

Let me know how you get on with that and if you need more help please let me know.

On Sun, May 26, 2024 at 11:02 AM BogdanJak @.***> wrote:

Beginnings are always difficult

— Reply to this email directly, view it on GitHub https://github.com/frankhale/toby-blazor/issues/11#issuecomment-2132251879, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABONSSR2GWYCD4QPZ24YKTZEH2O5AVCNFSM6AAAAABIGGSR2KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZSGI2TCOBXHE . You are receiving this because you modified the open/close state.Message ID: @.***>

BogdanJak commented 5 months ago

In another application, the Youtube player works fine - but bypassing the modal window. However, in my code sample I have a problem opening the VideoPopup.razor modal window. Since Java is "black magic" for me, I asked for help in opening a modal window.

BogdanJak commented 5 months ago

Hi

  1. Attached is a video of the error I get when trying to play the same video clip again. I don't know why this happens.
  2. You can add to your application the ability to play all your favorite video clips in turn (without having to click individual clips - one button play all)

regards Bogdan

https://github.com/frankhale/toby-blazor/assets/54505464/a9b376ef-d9ac-4e9e-a2de-21beb84cd584

frankhale commented 5 months ago

I suspect that there are some issues with how the YouTube iframe API is being used. It's quite possible that some of the state of the YouTube API is being corrupted by accident due to probably errors on my part and the fact that the Blazor app was recently upgraded to .NET 8. Also this code is showing it's age especially the dirty JavaScript that is using jQuery.

This code attempts to initialize the YouTube API once and then reuse it. I think a better solution would be to load a fresh YouTube API on every video popup so that there is no way to corrupt the state of the player.