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 description for Form1.
'''
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
'''
''' Required designer variable.
'''
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
'''
''' Clean up any resources being used.
'''
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"
'''
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
'''
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("" & videoPath & "")
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
|