| Set fso = CreateObject("Scripting.FileSystemObject") |
| Set player = CreateObject("WMPlayer.OCX") |
| Set shell = CreateObject("WScript.Shell") |
| Dim configRegPath |
| configRegPath = "HKEY_CURRENT_USER\Software\YsVbsMusicPlayer\Config\" |
| Dim musicFolderPath, currentSongIndex, totalSongCount |
| On Error Resume Next |
| musicFolderPath = shell.RegRead(configRegPath & "MusicFolderPath") |
| If Err.Number <> 0 Then |
| musicFolderPath = "" |
| Err.Clear |
| End If |
| |
| currentSongIndex = shell.RegRead(configRegPath & "CurrentSongIndex") |
| If Err.Number <> 0 Then |
| currentSongIndex = 0 |
| Err.Clear |
| End If |
| |
| totalSongCount = shell.RegRead(configRegPath & "TotalSongCount") |
| If Err.Number <> 0 Then |
| totalSongCount = 0 |
| Err.Clear |
| End If |
| On Error Goto 0 |
| Do |
| musicFolderPath = InputBox(" 请看下面输入框中的音乐文件夹路径"& vbCrLf &""& vbCrLf &" 是否正确?如需更换,请输入新路径"& vbCrLf &""& vbCrLf &" 如果没问题,直接点确定开始播放。", "音乐路径输入", musicFolderPath) |
| If musicFolderPath = "" Then |
| WScript.Quit |
| Else |
| Exit Do |
| End If |
| Loop |
| |
| If Not fso.FolderExists(musicFolderPath) Then |
| Do |
| WScript.Echo "音乐文件夹路径不存在,请输入正确的音乐文件夹路径。" |
| Do |
| musicFolderPath = InputBox("请输入有效的MP3音乐文件夹路径", "音乐路径输入") |
| If musicFolderPath = "" Then |
| WScript.Quit |
| Else |
| Exit Do |
| End If |
| Loop |
| Loop Until fso.FolderExists(musicFolderPath) |
| End If |
| Dim hasMP3Files |
| hasMP3Files = False |
| If fso.FolderExists(musicFolderPath) Then |
| Dim newTotalSongCount |
| newTotalSongCount = 0 |
| For Each file In fso.GetFolder(musicFolderPath).Files |
| If LCase(fso.GetExtensionName(file.Name)) = "mp3" Then |
| hasMP3Files = True |
| newTotalSongCount = newTotalSongCount + 1 |
| End If |
| Next |
| If newTotalSongCount <> totalSongCount Then |
| currentSongIndex = 0 |
| totalSongCount = newTotalSongCount |
| End If |
| End If |
| If Not hasMP3Files Then |
| Do |
| WScript.Echo "指定路径下没有MP3文件,请重新输入。" |
| Do |
| musicFolderPath = InputBox("请输入包含MP3文件的音乐文件夹路径", "音乐路径输入") |
| If musicFolderPath = "" Then |
| WScript.Quit |
| Else |
| Exit Do |
| End If |
| Loop |
| hasMP3Files = False |
| If fso.FolderExists(musicFolderPath) Then |
| Dim newTotalSongCount2 |
| newTotalSongCount2 = 0 |
| For Each file In fso.GetFolder(musicFolderPath).Files |
| If LCase(fso.GetExtensionName(file.Name)) = "mp3" Then |
| hasMP3Files = True |
| newTotalSongCount2 = newTotalSongCount2 + 1 |
| End If |
| Next |
| If newTotalSongCount2 <> totalSongCount Then |
| currentSongIndex = 0 |
| totalSongCount = newTotalSongCount2 |
| End If |
| End If |
| Loop Until hasMP3Files |
| End If |
| shell.RegWrite configRegPath & "MusicFolderPath", musicFolderPath, "REG_SZ" |
| shell.RegWrite configRegPath & "TotalSongCount", totalSongCount, "REG_DWORD" |
| shell.RegWrite configRegPath & "CurrentSongIndex", currentSongIndex, "REG_DWORD" |
| Set musicFolder = fso.GetFolder(musicFolderPath) |
| Dim songs() |
| ReDim songs(-1) |
| For Each file In musicFolder.Files |
| If LCase(fso.GetExtensionName(file.Name)) = "mp3" Then |
| ReDim Preserve songs(UBound(songs) + 1) |
| songs(UBound(songs)) = fso.GetBaseName(file.Name) |
| End If |
| Next |
| If UBound(songs) < 0 Then |
| WScript.Echo "没有找到MP3文件,请检查路径。" |
| WScript.Quit |
| End If |
| On Error Resume Next |
| Do While True |
| player.URL = musicFolderPath & "\" & songs(currentSongIndex) & ".mp3" |
| player.settings.setMode "loop", True |
| |
| Do While player.playState <> 3 And player.playState <> 1 |
| WScript.Sleep 100 |
| Loop |
| If Err.Number <> 0 Then |
| WScript.Echo "播放出错:" & Err.Description |
| Err.Clear |
| End If |
| |
| Do While player.playState = 3 |
| Dim userChoice |
| userChoice = MsgBox("正在播放:" & (currentSongIndex + 1) & "." & songs(currentSongIndex) & vbCrLf & _ |
| "点【是】-> 播放【上一曲】" & vbCrLf & _ |
| "点【否】-> 播放【下一曲】" & vbCrLf & _ |
| "点【取消】-> 选择播放模式", _ |
| vbYesNoCancel + vbQuestion, (currentSongIndex + 1) & "." & songs(currentSongIndex) & " - " & "VBS音乐播放器V3") |
| If userChoice = vbYes Then |
| If currentSongIndex > 0 Then |
| currentSongIndex = currentSongIndex - 1 |
| Else |
| WScript.Echo "亲,这是已经是第一首咯。" |
| End If |
| player.controls.stop |
| Exit Do |
| ElseIf userChoice = vbNo Then |
| currentSongIndex = currentSongIndex + 1 |
| If currentSongIndex > UBound(songs) Then |
| currentSongIndex = 0 |
| WScript.Echo "亲,这是最后一首咯,现在从头开始播放。" |
| End If |
| player.controls.stop |
| Exit Do |
| ElseIf userChoice = vbCancel Then |
| Dim loopChoice |
| loopChoice = MsgBox("正在播放:" & (currentSongIndex + 1) & "." & songs(currentSongIndex) & vbCrLf & _ |
| "点【是】-> 全曲循环播放" & vbCrLf & _ |
| "点【否】-> 返回主界面" & vbCrLf & _ |
| "点【取消】-> 退出播放器", _ |
| vbYesNoCancel + vbQuestion, "音乐循环模式") |
| If loopChoice = vbYes Then |
| player.settings.setMode "loop", False |
| Do While True |
| player.URL = musicFolderPath & "\" & songs(currentSongIndex) & ".mp3" |
| Do While player.playState <> 3 And player.playState <> 1 |
| WScript.Sleep 100 |
| Loop |
| If Err.Number <> 0 Then |
| WScript.Echo "播放出错:" & Err.Description |
| Err.Clear |
| End If |
| Do While player.playState = 3 |
| WScript.Sleep 100 |
| Loop |
| currentSongIndex = currentSongIndex + 1 |
| If currentSongIndex > UBound(songs) Then |
| currentSongIndex = 0 |
| End If |
| shell.RegWrite configRegPath & "CurrentSongIndex", currentSongIndex, "REG_DWORD" |
| Loop |
| ElseIf loopChoice = vbNo Then |
| player.settings.setMode "loop", True |
| Exit Do |
| ElseIf loopChoice = vbCancel Then |
| WScript.Quit |
| End If |
| End If |
| Do While player.playState = 3 |
| WScript.Sleep 100 |
| Loop |
| Loop |
| If player.playState <> 1 Then |
| player.controls.stop |
| End If |
| Loop |
| On Error Goto 0 |
| player.close |
| Set player = Nothing |
| Set fso = Nothing |
| Set shell = NothingCOPY |