• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2556
  • Last Modified:

Play flv file in VB.NET Form

Hi I have movie trailer in FLV format (9MB) I would like to play it in VB.NET WIndows Form ...
0
_ColdFire_
Asked:
_ColdFire_
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
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
http://www.codeproject.com/KB/audio-video/flashexternalapi.aspx
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 
            ' 
            InitializeComponent() 
            
            Try 
                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.") 
                Me.Dispose() 
            End Try 
        End Sub 
        
        Public Sub New(ByVal moviePath As String) 
            Me.New() 
            Me.LoadVideo(moviePath) 
        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 
                    components.Dispose() 
                End If 
            End If 
            MyBase.Dispose(disposing) 
        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() 
            Me.videoPlaceholder.SuspendLayout() 
            DirectCast((Me.flashPlayer), System.ComponentModel.ISupportInitialize).BeginInit() 
            Me.SuspendLayout() 
            ' 
            ' 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.Controls.Add(Me.flashPlayer) 
            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.Controls.Add(Me.statusbar) 
            Me.Controls.Add(Me.openVideo) 
            Me.Controls.Add(Me.videoPlaceholder) 
            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() 
            Me.videoPlaceholder.ResumeLayout(False) 
            DirectCast((Me.flashPlayer), System.ComponentModel.ISupportInitialize).EndInit() 
                
            Me.ResumeLayout(False) 
        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 
                LoadVideo(openVideoDialog.FileName) 
            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 
                LoadVideo(files(0)) 
            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() 
            document.LoadXml(e.request) 
            
            ' 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

0
 
Meir RivkinFull stack Software EngineerCommented:
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.

0
 
Meir RivkinFull stack Software EngineerCommented:
0
 
_ColdFire_Author Commented:
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?
0
 
_ColdFire_Author Commented:
it doesnt play flv files , just flash.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now