@page "/" @inject IJSRuntime theJavaScriptEngine; <!-- Buttons for interaction --> <button @onclick="StartVideo">Start video</button> <button @onclick="RepeatExcercises">Repeat Excercises</button> <button @onclick="ModifyUrl"> Modify Url (of Two Sided Videos)</button> <!-- Video Element --> <div class="align-content-center"> <video id="videoTagId" autoplay width="1080" height="720" @onended="NextVideo"> <source id="videoSourceId" src="@Videos[selected_video_id].CurrentUrl" type="video/mp4"/> </video> </div> <!-- Developer output --> @foreach(var v in Videos) { <li><code>Name: </code>@v.Name</li> <li><code>Video Current URl</code>@v.CurrentUrl</li> <li><code>Video URl 1</code>@v.Url1</li> <li><code>Video URL 2</code>@v.Url2</li> <li><code>Two Sided</code>@v.TwoSided</li> <li>...</li> } @code { public int selected_video_id { get; set; } = 0; public IList<ExcerciseVideo>? Videos; // The list we use to store the Videos public int Repetitions { get; set; } = 2; // we want each exercise two times public string sidePlayNext {get; set; } = "left"; public class ExcerciseVideo { public string Name { get; set; } public string CurrentUrl { get; set; } public string Url1 { get; set; } public string Url2{ get; set; } // right hand side of each excercise public bool TwoSided { get; set; } } protected override void OnInitialized() { Videos = new List<ExcerciseVideo>() { new ExcerciseVideo { Name="Excercise A", CurrentUrl = "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4", Url1="https://backtrainingapp.blob.core.windows.net/backtrainingvideos/20220220_184806[1].mp4", Url2="https://backtrainingapp.blob.core.windows.net/backtrainingvideos/20220220_184806[1].mp4", TwoSided=false}, new ExcerciseVideo { Name="Excercise B", CurrentUrl = "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4", Url1="https://backtrainingapp.blob.core.windows.net/backtrainingvideos/20220220_184632[1].mp4", Url2="https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4", TwoSided=true} }; } public void RepeatExcercises() { // obtain values of the Video List int old_video_count = Videos.Count; int my_index = 0; // Create a copy of the Video List IList<ExcerciseVideo> originalVideos = new List<ExcerciseVideo>(Videos); Videos.Clear(); // Clear the list --> we need a clean list for item insertion (in order to not have old items included) // we loop over the list to repeat Videos // and insert them for (int l = 0; l < old_video_count; l++) { for (int repeats = 0; repeats < Repetitions; repeats++) { Videos.Insert(my_index, originalVideos[l]); my_index++; // increment the index } } StateHasChanged(); // Make sure that the changes are updated } // Modify the Url of twoSided Videos public void ModifyUrl() { for (int m = 0; m < Videos.Count; m++) { // check whether a video is twosided if (Videos[m].TwoSided == true) { // check whether left side should be played // set Url1 in this case as value if (sidePlayNext == "left") { Videos[m].CurrentUrl = Videos[m].Url1; Console.WriteLine(sidePlayNext); Console.WriteLine(Videos[m].CurrentUrl); sidePlayNext = "right"; } // check whether right side should be played // set Url2 in this case as value else if (sidePlayNext == "right") { Videos[m].CurrentUrl = Videos[m].Url2; Console.WriteLine(sidePlayNext); Console.WriteLine(Videos[m].CurrentUrl); sidePlayNext = "left"; } } // All other cases in which no two sided videos are present // --> Current URl should correspond to Url1 else if (Videos[m].TwoSided == false) { Videos[m].CurrentUrl = Videos[m].Url1; Console.WriteLine("No Direction"); Console.WriteLine(Videos[m].CurrentUrl); } } StateHasChanged(); } protected void StartVideo() { selected_video_id = 0; theJavaScriptEngine.InvokeVoidAsync("loadVideo"); } protected void NextVideo() { selected_video_id = selected_video_id + 1; theJavaScriptEngine.InvokeVoidAsync("loadVideo"); } }
namespace BlazorFiddleProject { using Microsoft.AspNetCore.Components.Builder; using Microsoft.Extensions.DependencyInjection; public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IComponentsApplicationBuilder app) { app.AddComponent<App>("app"); } } }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width"> <title>BlazorFiddleProject</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <script src="_content/MatBlazor/dist/matBlazor.js"></script> <style> app { } </style> <script type="text/javascript"> </script> </head> <body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> <script> function loadVideo() { document.getElementById("videoTagId").load(); } </script> </body> </html>

Add component

BlazorFiddle was updated from Blazor 0.7 to .NET 6.0. Your old source code could not work. You need to upgrade to latest.