how to open and play video files in windows form? also save videos in a specific folder inside the project. i am new to .net.please help.
thanks in advance :)

Dani AI

Generated

: was right that you have options — Windows Media Player control is the simplest to embed in a WinForms app, while VLC/LibVLC gives far better codec support. The problem you describe (first file plays but switching files leaves the old one running) normally means the code never stops or replaces the currently loaded media before starting the next one. The simplest, reliable pattern is: stop the current player, copy/load the new file, then play it.

Example (VB.NET + Windows Media Player COM control dropped on the form as AxWindowsMediaPlayer1):

Imports System.IO

Private Sub OpenAndPlay()
    Using ofd As New OpenFileDialog()
        ofd.Filter = "Video Files|*.mp4;*.avi;*.mkv;*.wmv|All Files|*.*"
        If ofd.ShowDialog() <> DialogResult.OK Then Return

        Dim source = ofd.FileName
        Dim targetDir = Path.Combine(Application.StartupPath, "Videos")
        If Not Directory.Exists(targetDir) Then Directory.CreateDirectory(targetDir)

        Dim dest = Path.Combine(targetDir, Path.GetFileName(source))
        File.Copy(source, dest, True)

        AxWindowsMediaPlayer1.Ctlcontrols.stop()
        AxWindowsMediaPlayer1.URL = dest
        AxWindowsMediaPlayer1.Ctlcontrols.play()
    End Using
End Sub

If you are embedding VLC (VLC ActiveX, Vlc.DotNet, LibVLCSharp, etc.), the same idea applies: call the control's Stop/MediaPlayer.Stop method, clear any playlist if needed, then load the new media and Play. If the old video keeps playing, confirm you are calling Stop on the same control instance (not a second process), and watch for exceptions when loading the new file.

Important cautions: writing into the application's install folder can fail on modern Windows (Program Files). For deployment, save videos to a writable location (user profile or AppData) or make the save folder configurable. Also remember Windows Media Player control uses system codecs — use VLC/LibVLC if you need wide format support.

Recommended Answers

All 2 Replies

Use WindowMedia control to play video onto the Windows Form but I suggest you to use WPF application. Take a look at -

i used vlc player control..i can play it the first time.when i select another file,there is no effect..previous movie continues to play..can anyone giv me the code to play a file in vlc..and to stop playing the current,and play another file on being opened. please help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.