C# WebView2 and viewing local HTML files with YouTube embedded in <iframe>
asked 9 hours ago by @qa-ffjhsoflhivvx8ljpgzf 0 rep · 81 views
c# iframe youtube webview2 liveserver
I asked this question about viewing local HTML files with YouTube embedded in <iframe> in my browser.
Local HTML file embed youtube with <iframe>
It was answered that it couldn't be done the best way was to use Visual Studio Code and Live Server. That worked great however if I want my family or friends want to view HTML files with YouTube embedded in <iframe> then I cant really expect them to install Visual Studio Code and Live Server. I am in the process of learning C# as well and I have created a few small apps. So I created an app with a WebView2 control and set the Source property to http://127.0.0.1:5500/testvideo.html
this is the testvideo.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Local Video Embed Test</title>
</head>
<body>
<h1>My Local Web Page</h1>
<!-- Paste your copied YouTube iframe code here -->
<iframe width="560" height="315"
src="https://www.youtube.com/embed/1IxxwvR6qSA?si=GjL_9UnP4EtQJTHs"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen>
</iframe>
</body>
</html>
When I run the Visual Studio Code and Live Server my C# app displays the Youtube iframe as expected in the WebView2 control. Obviously when I stop the Live Server the page cannot be displayed. My question is you guessed it, is there a way to add the Live Server functionality to my C# app without using Visual Studio Code and Live Server?