Play flv file in VB.NET Form

Posted on 2010-01-04
Last Modified: 2012-05-08
Hi I have movie trailer in FLV format (9MB) I would like to play it in VB.NET WIndows Form ...
Question by:_ColdFire_
    LVL 96

    Accepted Solution

    There are resources to be found, like this CodeProject article, that describes what you need to do to display a FLV file.

    Fun with C# and the Flash Player 8 External API
    Imports System 
    Imports System.Drawing 
    Imports System.Collections 
    Imports System.ComponentModel 
    Imports System.Windows.Forms 
    Imports System.Data 
    Imports System.IO 
    Imports System.Xml 
    Imports AxShockwaveFlashObjects 
    Namespace Vml.FLVPlayer 
        ''' <summary> 
        ''' Summary description for Form1. 
        ''' </summary> 
        Public Class FLVPlayer 
            Inherits System.Windows.Forms.Form 
            Private statusbar As StatusBar 
            Private fileNameStatusBarPanel As StatusBarPanel 
            Private videoPlaceholder As System.Windows.Forms.Panel 
            Private openVideo As System.Windows.Forms.Button 
            Private openVideoDialog As System.Windows.Forms.OpenFileDialog 
            Private flashPlayer As AxShockwaveFlashObjects.AxShockwaveFlash 
            ''' <summary> 
            ''' Required designer variable. 
            ''' </summary> 
            Private components As System.ComponentModel.Container = Nothing 
            Public Sub New() 
                ' Required for Windows Form Designer support 
                    flashPlayer.LoadMovie(0, Application.StartupPath & "\player.swf") 
                    AddHandler flashPlayer.FlashCall, AddressOf flashPlayer_FlashCall 
                Catch ex As Exception 
                    ExceptionUtilities.DisplayException("Unable to load SWF video player, please verify you have Flash Player 8 installed and try again.") 
                End Try 
            End Sub 
            Public Sub New(ByVal moviePath As String) 
            End Sub 
            ''' <summary> 
            ''' Clean up any resources being used. 
            ''' </summary> 
            Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) 
                If disposing Then 
                    If components IsNot Nothing Then 
                    End If 
                End If 
            End Sub 
            #Region "Windows Form Designer generated code" 
            ''' <summary> 
            ''' Required method for Designer support - do not modify 
            ''' the contents of this method with the code editor. 
            ''' </summary> 
            Private Sub InitializeComponent() 
                Dim resources As New System.Resources.ResourceManager(GetType(FLVPlayer)) 
                Me.openVideo = New System.Windows.Forms.Button() 
                Me.openVideoDialog = New System.Windows.Forms.OpenFileDialog() 
                Me.statusbar = New System.Windows.Forms.StatusBar() 
                Me.fileNameStatusBarPanel = New System.Windows.Forms.StatusBarPanel() 
                Me.videoPlaceholder = New System.Windows.Forms.Panel() 
                Me.flashPlayer = New AxShockwaveFlashObjects.AxShockwaveFlash() 
                DirectCast((Me.fileNameStatusBarPanel), System.ComponentModel.ISupportInitialize).BeginInit() 
                DirectCast((Me.flashPlayer), System.ComponentModel.ISupportInitialize).BeginInit() 
                ' openVideo 
                Me.openVideo.FlatStyle = System.Windows.Forms.FlatStyle.System 
                Me.openVideo.Location = New System.Drawing.Point(8, 272) 
                Me.openVideo.Name = "openVideo" 
                Me.openVideo.Size = New System.Drawing.Size(88, 23) 
                Me.openVideo.TabIndex = 1 
                Me.openVideo.Text = "Open..." 
                AddHandler Me.openVideo.Click, AddressOf Me.openVideo_Click 
                ' statusbar 
                Me.statusbar.Location = New System.Drawing.Point(0, 298) 
                Me.statusbar.Name = "statusbar" 
                Me.statusbar.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.fileNameStatusBarPanel}) 
                Me.statusbar.ShowPanels = True 
                Me.statusbar.Size = New System.Drawing.Size(338, 22) 
                Me.statusbar.SizingGrip = False 
                Me.statusbar.TabIndex = 4 
                ' fileNameStatusBarPanel 
                Me.fileNameStatusBarPanel.Text = "File not loaded" 
                Me.fileNameStatusBarPanel.ToolTipText = "The file currently loaded" 
                Me.fileNameStatusBarPanel.Width = 810 
                ' videoPlaceholder 
                Me.videoPlaceholder.BackColor = System.Drawing.Color.Black 
                Me.videoPlaceholder.Location = New System.Drawing.Point(8, 8) 
                Me.videoPlaceholder.Name = "videoPlaceholder" 
                Me.videoPlaceholder.Size = New System.Drawing.Size(320, 240) 
                Me.videoPlaceholder.TabIndex = 6 
                ' flashPlayer 
                Me.flashPlayer.ContainingControl = Me 
                Me.flashPlayer.Enabled = True 
                Me.flashPlayer.Location = New System.Drawing.Point(0, 0) 
                Me.flashPlayer.Name = "flashPlayer" 
                Me.flashPlayer.OcxState = DirectCast((resources.GetObject("flashPlayer.OcxState")), System.Windows.Forms.AxHost.State) 
                Me.flashPlayer.Size = New System.Drawing.Size(40, 24) 
                Me.flashPlayer.TabIndex = 0 
                ' FLVPlayer 
                Me.AccessibleName = "FLVPlayer" 
                Me.AllowDrop = True 
                Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) 
                Me.ClientSize = New System.Drawing.Size(338, 320) 
                Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle 
                Me.Icon = DirectCast((resources.GetObject("$this.Icon")), System.Drawing.Icon) 
                Me.MaximizeBox = False 
                Me.Name = "FLVPlayer" 
                Me.Text = "FLVPlayer" 
                AddHandler Me.DragDrop, AddressOf Me.FLVPlayer_DragDrop 
                AddHandler Me.DragEnter, AddressOf Me.FLVPlayer_DragEnter 
                DirectCast((Me.fileNameStatusBarPanel), System.ComponentModel.ISupportInitialize).EndInit() 
                DirectCast((Me.flashPlayer), System.ComponentModel.ISupportInitialize).EndInit() 
            End Sub 
            #End Region 
            Private Sub openVideo_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
                openVideoDialog = New OpenFileDialog() 
                openVideoDialog.Filter = "*.flv|*.flv" 
                openVideoDialog.Title = "Select a Flash Video file..." 
                openVideoDialog.Multiselect = False 
                openVideoDialog.RestoreDirectory = True 
                If openVideoDialog.ShowDialog() = DialogResult.OK Then 
                End If 
            End Sub 
            Private Sub LoadVideo(ByVal videoPath As String) 
                fileNameStatusBarPanel.Text = videoPath 
                flashPlayer.CallFunction("<invoke name=""loadAndPlayVideo"" returntype=""xml""><arguments><string>" & videoPath & "</string></arguments></invoke>") 
            End Sub 
            Private Sub FLVPlayer_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) 
                Dim files As String() = DirectCast(e.Data.GetData(DataFormats.FileDrop), String()) 
                If fileNameStatusBarPanel.Text <> files(0) Then 
                End If 
            End Sub 
            Private Sub FLVPlayer_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) 
                If e.Data.GetDataPresent(DataFormats.FileDrop, False) Then 
                    e.Effect = DragDropEffects.All 
                End If 
            End Sub 
            ' private void btnUrl_Click(object sender, System.EventArgs e) 
            ' { 
            ' UrlDialog urlForm = new UrlDialog(); 
            ' if(urlForm.ShowDialog(this) == DialogResult.OK) 
            ' { 
            ' if(urlForm.Url != null && urlForm.Url.Length > 0) 
            ' { 
            ' LoadVideo(urlForm.Url); 
            ' } 
            ' } 
            ' } 
            Public Sub ResizePlayer(ByVal width As Integer, ByVal height As Integer) 
                flashPlayer.Width = width 
                flashPlayer.Height = height 
                videoPlaceholder.Width = width 
                videoPlaceholder.Height = height 
            End Sub 
            Private Sub flashPlayer_FlashCall(ByVal sender As Object, ByVal e As _IShockwaveFlashEvents_FlashCallEvent) 
                Dim document As New XmlDocument() 
                ' Since I have only one call back I just grab the arguments and call 
                ' the function. This needs to be made much more flexible when there are 
                ' multiple call backs going back and forth 
                Dim list As XmlNodeList = document.GetElementsByTagName("arguments") 
                ResizePlayer(Convert.ToInt32(list(0).FirstChild.InnerText), Convert.ToInt32(list(0).ChildNodes(1).InnerText)) 
            End Sub 
        End Class 
    End Namespace

    Open in new window

    LVL 42

    Expert Comment

    if Flash is installed on your pc u can use the COM component "Shockwave Flash Object".
    just right click your toolbox, click Add/Remove Items and tick the "Shockwave Flash Object" in the COM Components" list.

    LVL 42

    Expert Comment


    Author Comment

    sedgwick: your solutions seems to be much easier , i accepted TheLearnedOne's solution because there was no others. When I'm using your method, i get an error when launching application. Microsoft saying:

    The program you were trying to install or use requires the latest version of Adobe Flash Player.

    To solve this problem, uninstall and then reinstall Adobe Flash Player by following these steps in the order given:
    Additional information for 64-bit browser users

    Adobe Flash Player is not currently supported in 64-bit browsers. You can run Adobe Flash Player in a 32-bit browser running on a 64-bit operating system. For more information, see the TechNote on the Adobe Systems Inc. website:

    I'm using Windows 7 x64, should I do something for program to use 32bit explorer?

    Author Comment

    it doesnt play flv files , just flash.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now