请问各位高手 在VB6.0中如何用MCI实现.avi,.adt 文件的播放 急急急!

解决方案 »

  1.   

    模块:
    Option ExplicitDeclare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
    Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long窗体(fom文件):
    VERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "播放多媒体文件"
       ClientHeight    =   3612
       ClientLeft      =   60
       ClientTop       =   348
       ClientWidth     =   4728
       LinkTopic       =   "Form1"
       ScaleHeight     =   3612
       ScaleWidth      =   4728
       StartUpPosition =   3  '窗口缺省
       Begin VB.CommandButton Command4 
          Caption         =   "重置"
          Height          =   375
          Left            =   2760
          TabIndex        =   9
          Top             =   2640
          Width           =   735
       End
       Begin VB.Timer Timer1 
          Interval        =   10
          Left            =   3480
          Top             =   0
       End
       Begin VB.HScrollBar HScroll1 
          Enabled         =   0   'False
          Height          =   255
          Left            =   240
          TabIndex        =   8
          Top             =   3240
          Width           =   4335
       End
       Begin VB.CommandButton Command1 
          Caption         =   "开启"
          Height          =   375
          Left            =   240
          TabIndex        =   7
          Top             =   2640
          Width           =   735
       End
       Begin VB.CommandButton Command5 
          Caption         =   "关闭"
          Height          =   375
          Left            =   3600
          TabIndex        =   6
          Top             =   2640
          Width           =   735
       End
       Begin VB.CommandButton Command3 
          Caption         =   "暂停"
          Height          =   375
          Left            =   1920
          TabIndex        =   5
          Top             =   2640
          Width           =   735
       End
       Begin VB.CommandButton Command2 
          Caption         =   "播放"
          Height          =   375
          Left            =   1080
          TabIndex        =   4
          Top             =   2640
          Width           =   735
       End
       Begin VB.FileListBox File1 
          Height          =   2052
          Left            =   2160
          Pattern         =   "*.wav;*.mid;*.avi"
          TabIndex        =   2
          Top             =   480
          Width           =   2295
       End
       Begin VB.DirListBox Dir1 
          Height          =   1560
          Left            =   240
          TabIndex        =   1
          Top             =   960
          Width           =   1815
       End
       Begin VB.DriveListBox Drive1 
          Height          =   300
          Left            =   240
          TabIndex        =   0
          Top             =   480
          Width           =   1815
       End
       Begin VB.Label Label1 
          AutoSize        =   -1  'True
          Caption         =   "请选择 .wav.mid.avi 文件"
          Height          =   180
          Left            =   120
          TabIndex        =   3
          Top             =   120
          Width           =   2604
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option ExplicitPrivate Sub Command1_Click()
        Dim PathName As String, S As String, ShortPathName As String
        Dim ret As Long
        
        PathName = File1.Path
        If Right(PathName, 1) <> "\" Then PathName = PathName & "\"
        PathName = PathName & File1.FileName
        
        S = String(LenB(PathName), Chr(0))
        GetShortPathName PathName, S, Len(S)
        ShortPathName = Left(S, InStr(S, Chr(0)) - 1)    mciSendString "close MyMedia", vbNullString, 0, 0
        ret = mciSendString("open " & ShortPathName & " alias MyMedia", vbNullString, 0, 0)
        If ret = 0 Then Caption = "播放多媒体文件 -- 已开启" & PathName
        
        S = String(256, Chr(0))
        mciSendString "status MyMedia length", S, Len(S), 0
        
        HScroll1.Max = Val(S)
        HScroll1.Min = 0
        HScroll1.SmallChange = IIf(HScroll1.Max \ 100 > 0, HScroll1.Max \ 100, 1)
        HScroll1.LargeChange = IIf(HScroll1.Max \ 10 > 0, HScroll1.Max \ 10, 1)
        
        HScroll1.Enabled = True
        
    End SubPrivate Sub Command2_Click()
        mciSendString "play MyMedia", vbNullString, 0, 0
    End SubPrivate Sub Command3_Click()
        mciSendString "pause MyMedia", vbNullString, 0, 0
    End SubPrivate Sub Command4_Click()
        Dim S As String
        
        mciSendString "seek MyMedia to start", vbNullString, 0, 0
        
        S = String(256, 0)
        mciSendString "status MyMedia position", S, Len(S), 0
        
        HScroll1.Value = Val(S)
    End SubPrivate Sub Command5_Click()
        mciSendString "close MyMedia", vbNullString, 0, 0
        Caption = "播放多媒体文件 -- 文件已关闭!"
        HScroll1.Enabled = False
    End SubPrivate Sub Dir1_Change()
        File1.Path = Dir1.Path
    End SubPrivate Sub Drive1_Change()
        Dir1.Path = Drive1.Drive
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        mciSendString "close MyMedia", vbNullString, 0, 0
    End SubPrivate Sub HScroll1_Change()
        Dim S As String
        
        S = String(256, 0)
        mciSendString "status MyMedia mode", S, Len(S), 0
        If Left(S, 7) = "playing" Or Left(S, 2) = "播放" Then Exit Sub
        
        mciSendString "seek MyMedia to " & HScroll1.Value, vbNullString, 0, 0
    End SubPrivate Sub Timer1_Timer()
        Dim S As String, ret As Long
        
        S = String(256, 0)
        ret = mciSendString("status MyMedia mode", S, Len(S), 0)
        If ret <> 0 Or Left(S, 7) = "stopped" Or Left(S, 2) = "停止" Then
            Exit Sub
        End If
        
        S = String(256, 0)
        mciSendString "status MyMedia position", S, Len(S), 0
        
        HScroll1.Value = Val(S)
    End Sub
      

  2.   

    Command1_Click()
    内的第19行:
    原来: HScroll1.Max = Val(S)
    改成:HScroll1.Max = Val(S) + 1