Play (Embed) m3u8 video using C# and VB.Net in Windows Forms Application

satabeach
 
on Jun 26, 2021 05:44 AM
Sample_144006.zip
1633 Views

How can I play m3u8 video using web URL in window forms application

I am using a windows media player to play, but it has buffering problems every 10 seconds.

When I checked using VLC player it works fine, does anybody have vlc library for windows forms or how can I play smoothly in windows media player in a windows forms application.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 28, 2021 02:08 AM

Hi satabeach,

Refer below sample.

Code

private void btnGo_Click(object sender, EventArgs e)
{
    string html = "<html><head>";
    html += "<meta content='IE=Edge' http-equiv='X-UA-Compatible'/>";
    html += "<link href='https://unpkg.com/video.js/dist/video-js.css' rel='stylesheet'>";
    html += "<script src='https://unpkg.com/video.js/dist/video.js'></script>";
    html += "<script src='https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js'></script>";
    html += "<video id='my_video' class='video-js vjs-fluid vjs-default-skin' controls preload='auto' data-setup='{}' autoplay>";
    html += "<source src='" + txtUrl.Text.Trim() + "' type='application/x-mpegURL'>";
    html += "</video>";
    html += "<script>";
    html += "var player = videojs('my_video');";
    html += "player.play();";
    html += "</script>";
    html += "</body></html>";
    this.webBrowser1.DocumentText = html;
}

VB.Net

Private Sub btnGo_Click(sender As System.Object, e As System.EventArgs) Handles btnGo.Click
    Dim html As String = "<html><head>"
    html += "<meta content='IE=Edge' http-equiv='X-UA-Compatible'/>"
    html += "<link href='https://unpkg.com/video.js/dist/video-js.css' rel='stylesheet'>"
    html += "<script src='https://unpkg.com/video.js/dist/video.js'></script>"
    html += "<script src='https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js'></script>"
    html += "<video id='my_video' class='video-js vjs-fluid vjs-default-skin' controls preload='auto' data-setup='{}' autoplay>"
    html += "<source src='" & txtUrl.Text.Trim() & "' type='application/x-mpegURL'>"
    html += "</video>"
    html += "<script>"
    html += "var player = videojs('my_video');"
    html += "player.play();"
    html += "</script>"
    html += "</body></html>"
    Me.webBrowser1.DocumentText = html
End Sub

Screenshot