Public Class MainForm
    Inherits System.Windows.Forms.Form

    Private strFLVPath As String

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents CheckBoxEnableStandardContextMenu As System.Windows.Forms.CheckBox
    Friend WithEvents CheckBoxEnableSounds As System.Windows.Forms.CheckBox
    Friend WithEvents ButtonPlaySWF As System.Windows.Forms.Button
    Friend WithEvents ButtonPlayFLV As System.Windows.Forms.Button
    Friend WithEvents ButtonAbout As System.Windows.Forms.Button
    Friend WithEvents ButtonOrder As System.Windows.Forms.Button
    Friend WithEvents f_in_box__control1 As f_in_box__lib.f_in_box__control
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.CheckBoxEnableStandardContextMenu = New System.Windows.Forms.CheckBox
        Me.CheckBoxEnableSounds = New System.Windows.Forms.CheckBox
        Me.ButtonPlaySWF = New System.Windows.Forms.Button
        Me.ButtonPlayFLV = New System.Windows.Forms.Button
        Me.ButtonAbout = New System.Windows.Forms.Button
        Me.ButtonOrder = New System.Windows.Forms.Button
        Me.F_in_box__control1 = New f_in_box__lib.f_in_box__control
        Me.SuspendLayout()
        '
        'CheckBoxEnableStandardContextMenu
        '
        Me.CheckBoxEnableStandardContextMenu.Location = New System.Drawing.Point(8, 376)
        Me.CheckBoxEnableStandardContextMenu.Name = "CheckBoxEnableStandardContextMenu"
        Me.CheckBoxEnableStandardContextMenu.Size = New System.Drawing.Size(184, 24)
        Me.CheckBoxEnableStandardContextMenu.TabIndex = 1
        Me.CheckBoxEnableStandardContextMenu.Text = "Enable standard context menu"
        '
        'CheckBoxEnableSounds
        '
        Me.CheckBoxEnableSounds.Location = New System.Drawing.Point(208, 376)
        Me.CheckBoxEnableSounds.Name = "CheckBoxEnableSounds"
        Me.CheckBoxEnableSounds.TabIndex = 2
        Me.CheckBoxEnableSounds.Text = "Enable sounds"
        '
        'ButtonPlaySWF
        '
        Me.ButtonPlaySWF.Location = New System.Drawing.Point(8, 408)
        Me.ButtonPlaySWF.Name = "ButtonPlaySWF"
        Me.ButtonPlaySWF.Size = New System.Drawing.Size(120, 23)
        Me.ButtonPlaySWF.TabIndex = 3
        Me.ButtonPlaySWF.Text = "Play embedded SWF"
        '
        'ButtonPlayFLV
        '
        Me.ButtonPlayFLV.Location = New System.Drawing.Point(136, 408)
        Me.ButtonPlayFLV.Name = "ButtonPlayFLV"
        Me.ButtonPlayFLV.Size = New System.Drawing.Size(120, 23)
        Me.ButtonPlayFLV.TabIndex = 4
        Me.ButtonPlayFLV.Text = "Play embedded FLV"
        '
        'ButtonAbout
        '
        Me.ButtonAbout.Location = New System.Drawing.Point(448, 376)
        Me.ButtonAbout.Name = "ButtonAbout"
        Me.ButtonAbout.Size = New System.Drawing.Size(176, 23)
        Me.ButtonAbout.TabIndex = 5
        Me.ButtonAbout.Text = "More about F-IN-BOX"
        '
        'ButtonOrder
        '
        Me.ButtonOrder.Location = New System.Drawing.Point(448, 408)
        Me.ButtonOrder.Name = "ButtonOrder"
        Me.ButtonOrder.Size = New System.Drawing.Size(176, 23)
        Me.ButtonOrder.TabIndex = 6
        Me.ButtonOrder.Text = "Buy license"
        '
        'F_in_box__control1
        '
        Me.F_in_box__control1.FlashProperty_AlignMode = 0
        Me.F_in_box__control1.FlashProperty_AllowScriptAccess = ""
        Me.F_in_box__control1.FlashProperty_BackgroundColor = -1
        Me.F_in_box__control1.FlashProperty_Base = ""
        Me.F_in_box__control1.FlashProperty_BGColor = ""
        Me.F_in_box__control1.FlashProperty_DeviceFont = False
        Me.F_in_box__control1.FlashProperty_EmbedMovie = False
        Me.F_in_box__control1.FlashProperty_FlashVars = ""
        Me.F_in_box__control1.FlashProperty_FrameNum = -1
        Me.F_in_box__control1.FlashProperty_Loop = True
        Me.F_in_box__control1.FlashProperty_Menu = True
        Me.F_in_box__control1.FlashProperty_Movie = ""
        Me.F_in_box__control1.FlashProperty_MovieData = ""
        Me.F_in_box__control1.FlashProperty_Playing = True
        Me.F_in_box__control1.FlashProperty_Quality = 1
        Me.F_in_box__control1.FlashProperty_Quality2 = "High"
        Me.F_in_box__control1.FlashProperty_SAlign = ""
        Me.F_in_box__control1.FlashProperty_Scale = "ShowAll"
        Me.F_in_box__control1.FlashProperty_ScaleMode = 0
        Me.F_in_box__control1.FlashProperty_Stacking = ""
        Me.F_in_box__control1.FlashProperty_SWRemote = ""
        Me.F_in_box__control1.FlashProperty_WMode = "Window"
        Me.F_in_box__control1.Location = New System.Drawing.Point(8, 8)
        Me.F_in_box__control1.Name = "F_in_box__control1"
        Me.F_in_box__control1.Size = New System.Drawing.Size(616, 360)
        Me.F_in_box__control1.StandardMenu = False
        Me.F_in_box__control1.TabIndex = 7
        Me.F_in_box__control1.Text = "F_in_box__control1"
        '
        'MainForm
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(632, 446)
        Me.Controls.Add(Me.F_in_box__control1)
        Me.Controls.Add(Me.ButtonOrder)
        Me.Controls.Add(Me.ButtonAbout)
        Me.Controls.Add(Me.ButtonPlayFLV)
        Me.Controls.Add(Me.ButtonPlaySWF)
        Me.Controls.Add(Me.CheckBoxEnableSounds)
        Me.Controls.Add(Me.CheckBoxEnableStandardContextMenu)
        Me.MaximizeBox = False
        Me.Name = "MainForm"
        Me.Text = "Sample 2 - SWF Embedding and FLV Embedding"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CheckBoxEnableStandardContextMenu.Checked = f_in_box__control1.StandardMenu
        CheckBoxEnableSounds.Checked = f_in_box__control1.AxCode.SoundEnabled

        AddHandler f_in_box__control1.AxCode.OnLoadExternalResourceByFullPath, AddressOf OnLoadExternalResourceByFullPath

        f_in_box__control1.PutMovieFromStream(Me.GetType().Assembly.GetManifestResourceStream("Sample02_SWF_FLV_Embedding.movie.swf"))
        f_in_box__control1.FlashMethod_Play()
    End Sub

    Private Sub ButtonPlaySWF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPlaySWF.Click
        f_in_box__control1.PutMovieFromStream(Me.GetType().Assembly.GetManifestResourceStream("Sample02_SWF_FLV_Embedding.movie.swf"))
        f_in_box__control1.FlashMethod_Play()
    End Sub

    Private Sub ButtonPlayFLV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPlayFLV.Click
        f_in_box__control1.FlashProperty_FlashVars = "FLVPath=http://FLV/FlashVideo.flv"
        f_in_box__control1.PutMovieFromStream(Me.GetType().Assembly.GetManifestResourceStream("Sample02_SWF_FLV_Embedding.flvplayer.swf"))
        f_in_box__control1.FlashMethod_Play()
    End Sub

    Private Sub CheckBoxEnableStandardContextMenu_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxEnableStandardContextMenu.CheckedChanged
        f_in_box__control1.StandardMenu = CheckBoxEnableStandardContextMenu.Checked
    End Sub

    Private Sub CheckBoxEnableSounds_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxEnableSounds.CheckedChanged
        f_in_box__control1.AxCode.SoundEnabled = CheckBoxEnableSounds.Checked
    End Sub

    Private Sub OnLoadExternalResourceByFullPath(ByVal sender As Object, ByVal URL As String, ByVal Stream As System.IO.Stream, ByRef Handled As Boolean)
        If URL = "http://FLV/FlashVideo.flv" Then
            Dim FLVStream As System.IO.Stream = Me.GetType().Assembly.GetManifestResourceStream("Sample02_SWF_FLV_Embedding.flashvideo.flv")

            ' You can write all content right here, but if FLVStream is BIG it takes long time
            ' The form will be unaccessible for user all this time
            ' Another option is to save Stream and write content in a separate thread
            ' You can find code example in the sample Sample1_SWF_And_FLV_Player

            Const nSize As Integer = 64 * 1024

            Dim buffer(nSize) As Byte

            Dim nReadBytes As Integer

            While (True)
                nReadBytes = FLVStream.Read(buffer, 0, nSize)

                If 0 = nReadBytes Then Exit While

                Try
                    Stream.Write(buffer, 0, nReadBytes)
                Catch e As System.IO.IOException
                    ' Loading is interrupted
                    Exit While
                End Try
            End While

            Stream.Close()

            Handled = True
        End If
    End Sub

    Private Sub ButtonAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonAbout.Click
        System.Diagnostics.Process.Start("http://www.f-in-box.com/dotnet/")
    End Sub

    Private Sub ButtonOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonOrder.Click
        System.Diagnostics.Process.Start("http://www.f-in-box.com/dotnet/order.html")
    End Sub
End Class
