Play YouTube Videos In Desktop Applications Using C#

We can play YouTube videos in Windows/Desktop applications using C#. In this blog, let us see how.

Here, I have used WebBrowser Control and HTML iFrame for playing YouTube videos. I have used WinForms for design.
 

Form

 
In this form, I have appended WebBrowser Control where YouTUbe videos will be played.
 
Play Youtube Videos In Desktop Application Using C#
 
Code
 
On "Play" button, let us add this click event.
  1. using System;  
  2. using System.Windows.Forms;  
  3. namespace FormTest {  
  4.     public partial class Form2: Form {  
  5.         public Form2() {  
  6.             InitializeComponent();  
  7.         }  
  8.         private void btnPlay_Click(object sender, EventArgs e) {  
  9.             string html = "<html><head>";  
  10.             html += "<meta content='IE=Edge' http-equiv='X-UA-Compatible'/>";  
  11.             html += "<iframe id='video' src= 'https://www.youtube.com/embed/{0}' width='600' height='300' frameborder='0' allowfullscreen></iframe>";  
  12.             html += "</body></html>";  
  13.             this.webBrowser1.DocumentText = string.Format(html, txtLink.Text.Split('=')[1]);  
  14.         }  
  15.     }  
  16. }  
Result
 
Play Youtube Videos In Desktop Application Using C#
 

Conclusion

 
We can easily play YouTube videos in Windows/Desktop applications in C# with just a small trick.