vb 在form1中选择好音乐文件,在form2中自动播放
DimMinute,SecondAsLongPrivateSubCommand1_Click()Minute=InputBox("输入分钟数","倒计时时间")If(Mi...
Dim Minute, Second As Long
Private Sub Command1_Click()
Minute = InputBox("输入分钟数", "倒计时时间")
If (Minute = "") Then Exit Sub
Second = 60 * Minute
Label1.Caption = "倒计时时间为" & Minute & "分钟"
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
Label1.Caption = "已结束倒计时"
End Sub
Private Sub Dir1_Change()
End Sub
Private Sub Command4_Click()
Dim inputdata As String
CommonDialog1.Filter = "音乐文件.mp3|*.mp3|音乐文件.wav|*.wav|音乐文件.flac|*.flac"
CommonDialog1.Action = 1
File = CommonDialog1.FileName
If File = "" Then
Exit Sub
Else
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
Text1.Text = Text1.Text + inputdata + vbCrLf
Loop
Close #1
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Second < 0 Then
Timer1.Enabled = False
Form1.Hide
Form2.Show
Else
Label1.Caption = IIf(Second \ 3600 = 0, "00", IIf(Second \ 3600 < 10, "0" & Second \ 3600, Second \ 3600)) & ":" & IIf(Second \ 60 Mod 60 = 0, "00", IIf(Second \ 60 Mod 60 < 10, "0" & Second \ 60 Mod 60, Second \ 60 Mod 60)) & ":" & IIf(Second Mod 60 Mod 60 = 0, "00", IIf(Second Mod 60 Mod 60 < 10, "0" & Second Mod 60 Mod 60, Second Mod 60 Mod 60))
HScroll1.Value = (60 * Minute - Second) / (60 * Minute) * HScroll1.Max
Second = Second - 1
End If
End Sub
顺便指出哪里不正确,感激不尽~! 展开
Private Sub Command1_Click()
Minute = InputBox("输入分钟数", "倒计时时间")
If (Minute = "") Then Exit Sub
Second = 60 * Minute
Label1.Caption = "倒计时时间为" & Minute & "分钟"
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Command3_Click()
Timer1.Enabled = False
Label1.Caption = "已结束倒计时"
End Sub
Private Sub Dir1_Change()
End Sub
Private Sub Command4_Click()
Dim inputdata As String
CommonDialog1.Filter = "音乐文件.mp3|*.mp3|音乐文件.wav|*.wav|音乐文件.flac|*.flac"
CommonDialog1.Action = 1
File = CommonDialog1.FileName
If File = "" Then
Exit Sub
Else
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, inputdata
Text1.Text = Text1.Text + inputdata + vbCrLf
Loop
Close #1
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
End Sub
Private Sub Timer1_Timer()
If Second < 0 Then
Timer1.Enabled = False
Form1.Hide
Form2.Show
Else
Label1.Caption = IIf(Second \ 3600 = 0, "00", IIf(Second \ 3600 < 10, "0" & Second \ 3600, Second \ 3600)) & ":" & IIf(Second \ 60 Mod 60 = 0, "00", IIf(Second \ 60 Mod 60 < 10, "0" & Second \ 60 Mod 60, Second \ 60 Mod 60)) & ":" & IIf(Second Mod 60 Mod 60 = 0, "00", IIf(Second Mod 60 Mod 60 < 10, "0" & Second Mod 60 Mod 60, Second Mod 60 Mod 60))
HScroll1.Value = (60 * Minute - Second) / (60 * Minute) * HScroll1.Max
Second = Second - 1
End If
End Sub
顺便指出哪里不正确,感激不尽~! 展开
2个回答
展开全部
干吗要在 Form2中去播放呀?
不太明白你的想法。
你先参考一下这段代码(把你的原代码相应过程替换):
'添加部件: Windows Media Player
'窗口上画一个 MediaPlayer1控件、一个ListBox
Option Explicit
Private sMp3List() As String
Private strPath As String
Private Sub Command4_Click()
Dim i As Long
'要顺利打开多个文件,必须加大缓冲区大小(字节数)
'否则,选取较多文件时,会出现异常
On Error GoTo E_Exit
CommonDialog1.MaxFileSize = 9600
CommonDialog1.Flags = &H80204
CommonDialog1.Filter = "音乐文件.mp3|*.mp3|音乐文件.wav|*.wav|音乐文件.flac|*.flac"
CommonDialog1.FileName = "" '注意先清除
CommonDialog1.ShowOpen
sMp3List = Split(CommonDialog1.FileName, vbNullChar)
List1.Clear
'现在这个代码只是处理同一个文件夹下的多个文件
'如果要播放不同文件夹下的多个文件,要用另外的方法处理
strPath = sMp3List(0) & "\"
For i = 1 To UBound(sMp3List)
List1.AddItem sMp3List(i)
Next
' 用控件来播放,或调用其它播放接口。首先播放第1首
MediaPlayer1.FileName = strPath & sMp3List(1)
MediaPlayer1.Play
E_Exit:
End Sub
Private Sub List1_Click()
' 用控件来播放,或调用其它播放接口
MediaPlayer1.FileName = strPath & sMp3List(List1.ListIndex + 1)
MediaPlayer1.Play
End Sub
更多追问追答
追问
CommonDialog1.MaxFileSize = 9600
...
sMp3List = Split(CommonDialog1.FileName, vbNullChar)
为什么这几步都是未找到方法或数据成员?
追答
我对你很无语……
如果我的代码,运行会出这种提示,
那只能说明你的窗口中,没有CommonDialog1这个控件!
你在窗口中画一个就行了。
但是,如果没有这个控件,难道你的那个 Private Sub Command4_Click() 又能够运行吗?
既然都说到这儿了,那我还得再说一下了:
MediaPlayer1这个,我是用 MSDXM.ocx的 MediaPlayer控件来播放的。
如果你用wmp.dll的那个,又得改一下了。
不知道你这个又会不会改 >_<
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询