当前位置: 源码素材网 » VB教程 » 详情页

用VB播放Flv文件的具体实现方法

  •   时间:2019-04-13
  • 概述:Flash播放器

用VB播放Flv文件的具体实现方法和代码,并支持播放列表功能,后附的源码包中有其它所需资源的源码:

VERSION 5.00
Object = "{D27CDB6B-AE6D-11CF-96B8-444553540000}#1.0#0"; "Flash8.ocx"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form Form1
   BorderStyle     =   1  'Fixed Single
   Caption         =   "FLV播放器"
   ClientHeight    =   4035
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9630
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   4035
   ScaleWidth      =   9630
   StartUpPosition =   2  '屏幕中心
   Begin VB.PictureBox Pic2
      AutoSize        =   -1  'True
      Height          =   4065
      Left            =   660
      Picture         =   "Frm_main.frx":0000
      ScaleHeight     =   4005
      ScaleWidth      =   165
      TabIndex        =   8
      Top             =   5055
      Width           =   225
   End
   Begin VB.PictureBox Pic1
      AutoSize        =   -1  'True
      Height          =   4065
      Left            =   405
      Picture         =   "Frm_main.frx":1171
      ScaleHeight     =   4005
      ScaleWidth      =   165
      TabIndex        =   7
      Top             =   5055
      Width           =   225
   End
   Begin MSComDlg.CommonDialog CommonDialog1
      Left            =   8910
      Top             =   3285
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton Cmd_Exit
      Caption         =   "退出"
      Height          =   405
      Left            =   8565
      TabIndex        =   6
      Top             =   2175
      Width           =   945
   End
   Begin VB.CommandButton Cmd_Del
      Caption         =   "删除"
      Height          =   405
      Left            =   8565
      TabIndex        =   5
      Top             =   1485
      Width           =   945
   End
   Begin VB.ListBox List2
      Height          =   2760
      Left            =   4635
      TabIndex        =   4
      Top             =   5235
      Width           =   1980
   End
   Begin VB.ListBox List1
      Height          =   3840
      Left            =   5760
      TabIndex        =   3
      Top             =   90
      Width           =   2595
   End
   Begin VB.CommandButton Cmd_Add
      Caption         =   "添加"
      Height          =   405
      Left            =   8565
      TabIndex        =   2
      Top             =   735
      Width           =   945
   End
   Begin VB.PictureBox Picture1
      BorderStyle     =   0  'None
      Height          =   4080
      Left            =   5310
      Picture         =   "Frm_main.frx":160A
      ScaleHeight     =   4080
      ScaleWidth      =   240
      TabIndex        =   1
      Top             =   15
      Width           =   240
   End
   Begin ShockwaveFlashObjectsCtl.ShockwaveFlash Flash1
      Height          =   3990
      Left            =   0
      TabIndex        =   0
      Top             =   15
      Width           =   5295
      _cx             =   9340
      _cy             =   7038
      FlashVars       =   ""
      Movie           =   ""
      Src             =   ""
      WMode           =   "Window"
      Play            =   -1  'True
      Loop            =   -1  'True
      Quality         =   "High"
      SAlign          =   ""
      Menu            =   -1  'True
      Base            =   ""
      AllowScriptAccess=   ""
      Scale           =   "ShowAll"
      DeviceFont      =   0   'False
      EmbedMovie      =   0   'False
      BGColor         =   ""
      SWRemote        =   ""
      MovieData       =   ""
      SeamlessTabbing =   -1  'True
      Profile         =   0   'False
      ProfileAddress  =   ""
      ProfilePort     =   0
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim xml As DOMDocument
Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long
Private Sub Cmd_Add_Click()   '添加
    CommonDialog1.Filter = "FLV文件(*.FLV)|*.flv"
    CommonDialog1.ShowOpen
    WriteXML (CommonDialog1.FileName)
    List2.AddItem CommonDialog1.FileName
    List1.AddItem FileName(CommonDialog1.FileName)
    WriteList
'    Flash1.Movie = App.Path & "\PlayFLV\FLVplayer.swf"
End Sub
Private Sub WriteXML(flvPath As String)
    Set xml = New DOMDocument
    'index.xml为描述图书信息的xml文档
    Call xml.Load(App.Path & "\PlayFLV\list.xml")
    Dim root As IXMLDOMElement
    Set root = xml.documentElement
    Dim node As IXMLDOMElement
    Dim nodePath As IXMLDOMNode
    Set nodePath = xml.selectSingleNode("flvLists/item")
    Set node = nodePath
    node.setAttribute "title", flvPath
    xml.save App.Path & "\PlayFLV\list.xml"
End Sub
Private Sub Cmd_Del_Click()   '删除
    If List1.ListIndex = -1 Then
        MsgBox "请选择要删除的文件"
        Exit Sub
    Else
        List2.RemoveItem (List1.ListIndex)
        List1.RemoveItem (List1.ListIndex)
    End If
    WriteList
End Sub
Private Sub Cmd_Exit_Click()
    On Error GoTo 11
    Unload Me
    Dim fs As New FileSystemObject
    If fs.FolderExists("C:\FLV") Then
11:        fs.DeleteFolder ("C:\FLV")
    End If

    End
End Sub
Private Sub Form_Load()
    On Error Resume Next
    Dim fs As New FileSystemObject
    fs.CreateFolder ("C:\FLV")
    Me.Width = 9780
    List1.Clear
    List2.Clear
    ReadList
End Sub
Private Sub List1_DblClick()
    Dim a
    Dim myFSO As New FileSystemObject
    Dim MyFolder As Folder
    Dim MyFile As File
    Dim i As Integer
    Set MyFolder = myFSO.GetFolder("C:\FLV\")
    i = 0
    For Each MyFile In MyFolder.Files
        i = i + 1
    Next
    a = CopyFile((List2.List(List1.ListIndex)), "C:\FLV\" & i & ".flv", False)
    WriteXML "C:\FLV\" & i & ".flv"
    Unload Me
    Me.Show
    Flash1.Movie = App.Path & "\PlayFLV\FLVplayer.swf"
End Sub
Private Sub Picture1_Click()  '显示与隐藏列表
    If Me.Width = 9780 Then
        Me.Width = 5610
        Picture1.Picture = Pic2.Picture
    ElseIf Me.Width = 5610 Then
        Me.Width = 9780
        Picture1.Picture = Pic1.Picture
    End If
End Sub
Public Function FileName(LoadFile As String) As String     '分析出 文件名称
    FileName = Trim$(Mid(Mid(LoadFile, 1, Len(LoadFile) - 4), _
                InStrRev(Mid(LoadFile, 1, Len(LoadFile) - 4), "\") + 1, 100))
End Function
Private Sub WriteList()
    Dim i As Integer
    Dim MyFile As String
    MyFile = App.Path & "\PlayList\PlayList.ini"
    '向文件中写入列表信息
    Open MyFile For Output As #1
    For i = 0 To List2.ListCount - 1
        List2.ListIndex = i
        Print #1, List2.Text,     '在文件中写入k的值
        Print #1,
    Next i
    Close 1
End Sub
Public Function ReadList() As String
    Dim sStr As String
    Dim aPath As String   '读取的文件路径
    Dim MyLine As String   '定义行变量
    sStr = ""
    aPath = App.Path & "\PlayList\PlayList.ini"
    Open aPath For Input As #1  ' 打开文件。
    Do While Not EOF(1)   ' 循环至文件尾。
        Line Input #1, MyLine   ' 读入一行数据并将其赋予某变量。
        List1.AddItem FileName(Trim(MyLine))
        List2.AddItem Trim(MyLine)
'        sStr = sStr & MyLine   ' 在立即窗口中显示数据。
    Loop
    Close #1   ' 关闭文件。
'    Readhtm = sStr
End Function

    相关内容:

    相关声明:

      若“用VB播放Flv文件的具体实现方法”有损您的权益,请告之我们删除内容。
      部分文章来源于网络,版权归原作者所有。