導航:首頁 > 編程語言 > 歌曲腳本代碼

歌曲腳本代碼

發布時間:2024-09-06 09:52:40

Ⅰ VB腳本怎麼寫啊

1、Private Sub Command1_Click()
Const msg1 As String="請在這里輸入你想顯示的一段話!"
Const msg2 As String="這里是對話框要顯示的標題."
MsgBox msg1,vbOkOnly,msg2 '此處代碼一定不能添加()
End Sub2、 form1按鈕點擊事件:
form2.show
form1.hide 3、
啟動VB程序,在窗體上放置6個命令按鈕,三個標簽,一個公用對話框、一個進度條、一個狀態欄和一個計時器,窗本的布置請參考附圖按鈕"Open MP3 File"是用來打開對話框選擇MP3文件,其他5個按鈕分別為Play(播放)、Pause(暫停)、Stopplay(停止播放)、Back(向後跳躍)、Prew(向前跳躍)。Label1用來表示歌曲當前時間;label2放在時度條的最左邊,Caption屬性為"00:00";lable3放在時度條的右邊,用來表示歌曲總長。下面就可以編寫代碼了。首先在窗體的"通用聲明"部分聲明函數

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrRetumString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Dim mfn As String
下面就是各個對象的代碼了:
Private Sub Form_load()
mfn = ""
play.Enabled = False
pause.Enabled = False
stopplay.Enabled = False
back.Enabled = False
prew.Enabled = False
Timer1.Enabled = False
Timer1.Interval = 500
End Sub
Private Sub open_Click()
On Error GoTo err
With CommonDialog1
.CancelError = True
.Filter = "音樂文件|*.mp3;*.wav;*.mid"
.Flags = cdlOFNNoChangeDir And cdlOFNPathMustExist
.Action = 1
stopplay_Click '停止按鈕同時可以設備初始化
mfn = .FileName '這個程序中文件名一定不能帶空格
Form1.Caption = .FileName
play.Enabled = True
End With
play_Click
Exit Sub
err:
End Sub
Private Sub play_Click()
On Error Resume Next
Dim t As Long
t = mciSendString("open " + mfn, 0&, 0, 0) 'Open後邊的空格一定不能丟
Dim ret As String * 128
t = mciSendString("status " + mfn + " length", ret, 128, 0)

'顯示歌曲總長
ret = Left(ret, 8)
If ret <> "" Then
ProgressBar1.min = 0
ProgressBar1.Max = Val(ret)
Label3.Caption = Gettime(Val(ret))
End If
play.Enabled = False
pause.Enabled = True
stopplay.Enabled = True
back.Enabled = True
prew.Enabled = True
t = mciSendString("status " + mfn + " mode", ret, 128, 0)
'得到設備的當前狀態,是播放還是暫停等等
ret = Left(ret, 8)
StatusBar1.Panels(1).Text = ret
'在狀態欄顯示播放狀態
t = mciSendString("play " + mfn + " form " + Str(ProgressBar1.Value), 0&, 0, 0)
'開始播放
Timer1.Enabled = True
End Sub
Private Sub pause_Click()
t% = mciSendString("pause " + mfn, 0&, 0, 0)
'發出暫停的命令
play.Enable = True
pause.Enabled = False
stopplay.Enabled = True
back.Enabled = False
prew.Enabled = False
End Sub
Private Sub stopplay_Click()
t% = mciSendString("stop " + mfn, 0&, 0, 0)
t% = mciSendString("close " + mfn, 0&, 0, 0)
'停止播放
play.Enabled = True
pause.Enabled = False
stopplay.Enabled = False
back.Enabled = False
prew.Enabled = False
End Sub
Private Sub back_Click()
t% = mciSendString("play " + mfn + " from " + Str(ProgressBar1.Value - (ProgressBar1.Max \ 10)), 0&, 0, 0) '向後跳一小段再播放
End Sub
Private Sub prew_Click()
t% = mciSendString("play " + mfn + " from " + Stri(ProgressBar1.Value + (ProgressBar1.Max \ 10)), 0&, 0, 0) '向前跳一小段再播放
End Sub

Private Sub Timer1_Timer()
Dim t As Long
Dim ret As String * 128
t = mciSendString("status " + mfn + " position", ret, 0, 0)
'得到當前播放位置
ret = Left(ret, 8)
ProgressBar1.Value = Val(ret)
Label1.Caption = Gettime(Val(ret))
'顯示歌曲當前時間
If ProgressBar1.Value = ProgressBar1.Max Then
stopplay_Click
End If
t = mciSendString("status " + mfn + " mode", ret, 128, 0)
ret = Left(ret, 8)
StatusBar1.Panels(1).Text = ret
End Sub
Private Sub Form_Unload(Cacel As Integer)
t% = mciSendString("stop " + mfn, 0&, 0, 0)
t% = mciSendString("close " + mfn, 0&, 0, 0)
End Sub
Private Function Gettime(position As Long) As String
'這個函數的功能是把以長整型表示的時間轉換為電子鍾式的"**:**"
Dim min, sec
min = position / 1000
min = min / 60
sec = min - Int(min)
min = Int(min)
sec = 60 * sec / 100
sec = Int(sec * 100)
Gettime = Str(min) + ":" + Str(sec)
End Function

閱讀全文

與歌曲腳本代碼相關的資料

熱點內容
python編程開發哪些崗位好 瀏覽:608
u盤的文件刪除後怎麼出個編號呢 瀏覽:961
java中forab什麼意思 瀏覽:5
資料庫導出文件格式 瀏覽:444
微信恢復接收文件 瀏覽:173
哪裡可以找到吃飯的app 瀏覽:736
xp屏保加密碼 瀏覽:436
重裝系統後顯示硬碟文件缺失 瀏覽:65
微信發送的文件都損壞了 瀏覽:402
大量計算用什麼編程方式好 瀏覽:241
編程器刷微星bios刷哪個文件 瀏覽:111
選擇小米手機3版本 瀏覽:314
iphone鏈接 瀏覽:110
9元編程課是什麼 瀏覽:436
cad為什麼不能輸入stl文件 瀏覽:78
編程與外語哪個更好就業 瀏覽:299
為什麼程序會跑飛 瀏覽:659
matlab中的m文件是什麼 瀏覽:226
excel批量保存pdf文件 瀏覽:963
win10文件夾死機動不了 瀏覽:411

友情鏈接