VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{C1A8AF28-1257-101B-8FB0-0020AF039CA3}#1.1#0"; "MCI32.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   Caption         =   "我的媒体播放机"
   ClientHeight    =   5055
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   7320
   LinkTopic       =   "Form1"
   ScaleHeight     =   5055
   ScaleWidth      =   7320
   StartUpPosition =   3  '窗口缺省
   Begin VB.ListBox List1 
      Height          =   4020
      Left            =   5640
      TabIndex        =   3
      Top             =   360
      Width           =   1455
   End
   Begin MSComctlLib.Slider Slider1 
      Height          =   495
      Left            =   1560
      TabIndex        =   2
      Top             =   4560
      Width           =   5535
      _ExtentX        =   9763
      _ExtentY        =   873
      _Version        =   393216
      Max             =   1
      TickStyle       =   3
   End
   Begin MCI.MMControl Mmci 
      Height          =   450
      Left            =   240
      TabIndex        =   1
      Top             =   4560
      Width           =   1260
      _ExtentX        =   2223
      _ExtentY        =   794
      _Version        =   393216
      PrevVisible     =   0   'False
      NextVisible     =   0   'False
      BackVisible     =   0   'False
      StepVisible     =   0   'False
      RecordVisible   =   0   'False
      EjectVisible    =   0   'False
      DeviceType      =   ""
      FileName        =   ""
   End
   Begin VB.PictureBox Winout 
      AutoRedraw      =   -1  'True
      Height          =   4335
      Left            =   240
      ScaleHeight     =   4275
      ScaleWidth      =   5235
      TabIndex        =   0
      Top             =   120
      Width           =   5295
   End
   Begin MSComDlg.CommonDialog OpenDlg 
      Left            =   -120
      Top             =   4440
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.Label Label1 
      Caption         =   "文件列表"
      Height          =   255
      Left            =   5640
      TabIndex        =   4
      Top             =   120
      Width           =   975
   End
   Begin VB.Menu menuFile 
      Caption         =   "文件"
      Begin VB.Menu menuOpen 
         Caption         =   "打开文件"
      End
      Begin VB.Menu menuPlayVcd 
         Caption         =   "播放vcd"
         Begin VB.Menu menuCDROM 
            Caption         =   "没有光驱"
            Index           =   0
         End
      End
      Begin VB.Menu menu001 
         Caption         =   "-"
      End
      Begin VB.Menu menuExit 
         Caption         =   "退出"
      End
   End
   Begin VB.Menu menuHelp 
      Caption         =   "帮助"
      Begin VB.Menu menuContent 
         Caption         =   "内容"
      End
      Begin VB.Menu menu002 
         Caption         =   "-"
      End
      Begin VB.Menu menuAbout 
         Caption         =   "关于播放器"
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim VcdPath As String

Private Sub Form_Load()
    '以毫秒为单位
    Mmci.TimeFormat = 0
    Mmci.Notify = True
    '获取光盘驱动器
    Dim fs, d, s, Index
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set d = fs.Drives  '驱动器集合
    Index = 0
    For Each s In d
        If s.DriveType = 4 Then     'CD-ROM的DriveType为4
            If Index <> 0 Then
                Load menuCDROM(Index)     '装入菜单
            End If
            '更改菜单标题
            menuCDROM(Index).Caption = s.DriveLetter + ":"
            Index = Index + 1
        End If
    Next

End Sub

Private Sub Form_Unload(Cancel As Integer)
    '别忘了关闭设备
    Mmci.Command = "Close"
End Sub

Private Sub List1_Click()
    Mmci.Command = "Close"
    Mmci.DeviceType = "MPEGVideo"    'VCD用的设备为MPEGVideo
    Mmci.FileName = VcdPath & "\" & List1.List(List1.ListIndex)
    Mmci.Command = "Open"
    '判断设备是否需要显示窗口，若需要，则设置为Winout
    If Mmci.UsesWindows Then
        Mmci.hWndDisplay = Winout.hWnd
    End If
    '用媒体的总长度设置Slider1的Max
    Slider1.Max = Mmci.Length
    '开始播放
    Mmci.Command = "Play"
End Sub

Private Sub menuAbout_Click()
    frmAbout.Show 1
End Sub


Private Sub menuCDROM_Click(Index As Integer)
    Dim fs, f, fc
    On Error Resume Next   '发生错误，则忽略到下一句
    '以下代码为读取mpegav目录下的所有文件
    List1.Clear
    VcdPath = menuCDROM(Index).Caption + "\mpegav"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(VcdPath)
    
    Set fc = f.Files
    For Each s In fc
        List1.AddItem s.Name
    Next
        
    '发生错误，表示没有找到VCD
    If Err Then
        MsgBox "没有发现VCD!"
    End If
    
End Sub

Private Sub menuOpen_Click()
    OpenDlg.DialogTitle = "请选择要播放的媒体文件"
    OpenDlg.Filter = "音频文件(*.wav,*.mp3)|*.wav;*.mp3|视频文件(*.avi,*.mpg)|*.avi;*.mpg|所有文件(*.*)|*.*"
    OpenDlg.ShowOpen
    If OpenDlg.FileName <> "" Then
        '播放媒体的代码放在下面
        Mmci.FileName = OpenDlg.FileName
        '如果设备已经打开，则关闭它。
        If Mmci.Mode <> mciModeNotOpen Then
            Mmci.Command = "Close"
        End If
        '打开设备
        Mmci.Command = "Open"
        
        '判断设备是否需要显示窗口，若需要，则设置为Winout
        If Mmci.UsesWindows Then
            Mmci.hWndDisplay = Winout.hWnd
        End If
        '用媒体的总长度设置Slider1的Max
        Slider1.Max = Mmci.Length
        
    End If
End Sub

Private Sub Mmci_Done(NotifyCode As Integer)
    '如果MCI正常完成，把位置定位到0
    If NotifyCode = 1 Then
        Mmci.To = 0
        Mmci.Command = "Seek"
    End If
End Sub

Private Sub Mmci_StatusUpdate()
    '媒体改变位置时，改变Slider1的值
    Slider1.Value = Mmci.Position
End Sub

Private Sub Slider1_Scroll()
    'Slider1发生改变时，对媒体重新定位
    Mmci.To = Slider1.Value
    Mmci.Command = "Seek"
End Sub

