VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain 
   Caption         =   "我的媒体播放机"
   ClientHeight    =   3225
   ClientLeft      =   165
   ClientTop       =   735
   ClientWidth     =   5295
   LinkTopic       =   "Form1"
   ScaleHeight     =   3225
   ScaleWidth      =   5295
   StartUpPosition =   3  '窗口缺省
   Begin MSComDlg.CommonDialog OpenDlg 
      Left            =   0
      Top             =   840
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton ButtonStop 
      Height          =   375
      Left            =   960
      Picture         =   "Form1.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   2640
      Width           =   375
   End
   Begin VB.CommandButton ButtonPause 
      Height          =   375
      Left            =   600
      Picture         =   "Form1.frx":0312
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   2640
      Width           =   375
   End
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   0
      Top             =   2160
   End
   Begin VB.CommandButton ButtonPlay 
      Height          =   375
      Left            =   240
      Picture         =   "Form1.frx":0624
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   2640
      Width           =   375
   End
   Begin VB.ListBox List1 
      Height          =   2040
      Left            =   3480
      TabIndex        =   2
      Top             =   360
      Width           =   1575
   End
   Begin MSComctlLib.Slider Slider1 
      Height          =   375
      Left            =   1320
      TabIndex        =   1
      Top             =   2640
      Width           =   3735
      _ExtentX        =   6588
      _ExtentY        =   661
      _Version        =   393216
      Max             =   1
      TickStyle       =   3
   End
   Begin VB.PictureBox Winout 
      AutoRedraw      =   -1  'True
      Height          =   2415
      Left            =   240
      ScaleHeight     =   2355
      ScaleWidth      =   2955
      TabIndex        =   0
      Top             =   120
      Width           =   3015
   End
   Begin VB.Label Label1 
      Caption         =   "文件列表"
      Height          =   255
      Left            =   3480
      TabIndex        =   3
      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 menuPlayProp 
      Caption         =   "播放属性"
      Begin VB.Menu menuFullScreen 
         Caption         =   "全屏"
      End
      Begin VB.Menu menu002 
         Caption         =   "-"
      End
      Begin VB.Menu menuSetVol 
         Caption         =   "音量设置"
      End
   End
   Begin VB.Menu menuHelp 
      Caption         =   "帮助"
      Begin VB.Menu menuContent 
         Caption         =   "内容"
      End
      Begin VB.Menu menu003 
         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 ButtonPause_Click()
    Exec_MciCmd "pause MyDev"
End Sub

Private Sub ButtonPlay_Click()
    Exec_MciCmd "play MyDev"
End Sub

Private Sub ButtonStop_Click()
    Exec_MciCmd "stop MyDev"
End Sub

Private Sub Form_Load()
    '以毫秒为单位
    '获取光盘驱动器
    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
    
    DevOpenFalg = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Exec_MciCmd "Close MyDev"
End Sub

Private Sub List1_Click()
    Open_MCIFile "MPEGVideo!" & VcdPath & "\" & List1.List(List1.ListIndex)
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 menuFullScreen_Click()
    Exec_MciCmd "play MyDev fullscreen"
End Sub

Private Sub menuOpen_Click()
    OpenDlg.DialogTitle = "请选择要播放的媒体文件"
    OpenDlg.Filter = "音频文件(*.wav,*.mp3)|*.wav;*.mp3|视频文件(*.avi)|*.avi|所有文件(*.*)|*.*"
    OpenDlg.ShowOpen
    If OpenDlg.FileName <> "" Then
        '播放媒体的代码放在下面
        Open_MCIFile OpenDlg.FileName
    End If
End Sub

Private Sub menuSetVol_Click()
    frmSelVol.Show 1
End Sub

Private Sub Slider1_Scroll()
    Dim lpStr As String
    Dim errCode As Integer
    On Error Resume Next   '发生错误，则忽略到下一句
    Timer1.Enabled = False
    errCode = Exec_MciCmd("status  MyDev mode wait", lpStr)
    Exec_MciCmd "seek  MyDev to " & Slider1.Value & " wait"
    If lpStr = "playing" Then
        Exec_MciCmd "play  MyDev "
    End If
    Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Dim lpStr As String
    Dim errCode As Integer
    On Error Resume Next   '发生错误，则忽略到下一句
    errCode = Exec_MciCmd("status  MyDev position", lpStr)
    If errCode = 0 Then
        Slider1.Value = Val(lpStr)
    End If
    
    errCode = Exec_MciCmd("status  MyDev mode wait", lpStr)

End Sub

Private Sub Open_MCIFile(nf As String)
    Dim lpStr As String
    Dim errCode As Integer
    
    Winout.Cls
    '如果设备已经打开，则关闭它。
    Exec_MciCmd "Close MyDev", lpStr
    '打开设备
    Exec_MciCmd "Open " & nf & " alias MyDev"
    '用媒体的总长度设置Slider1的Max
    errCode = Exec_MciCmd("set MyDev time format milliseconds", lpStr)
    errCode = Exec_MciCmd("status MyDev length wait", lpStr)
    If errCode = 0 Then Slider1.Max = Val(lpStr)
    '判断设备是否需要显示窗口，若需要，则设置为Winout
    errCode = Exec_MciCmd("window MyDev handle " & Winout.hWnd, lpStr)
End Sub
