R% = mciSendString&("OPEN C:\multi_files\vb\sm.wav TYPE waveaudio ALIAS NN", 0&, 0, 0)
R% = mciSendString&("PLAY NN FROM 0", 0&, 0, 0)
R% = mciSendString&("CLOSE ANIMATION", 0&, 0, 0)我这个程序,是给别人做的演示程序,怎样做才能使我的音乐在不同的机器上都能播放呢?因为到了不同的机器上音乐文件的路径就变了,我试了试app.path + "\sm.wav" 是不行的?
请教各位高手!
R% = mciSendString&("PLAY NN FROM 0", 0&, 0, 0)
R% = mciSendString&("CLOSE ANIMATION", 0&, 0, 0)我这个程序,是给别人做的演示程序,怎样做才能使我的音乐在不同的机器上都能播放呢?因为到了不同的机器上音乐文件的路径就变了,我试了试app.path + "\sm.wav" 是不行的?
请教各位高手!
' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
' and select Microsoft Common Dialog control)
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Dim Alias As String
Private Sub Form_Load() Const PlayTime = 10
'Set the common dialog box' title
CDBox.DialogTitle = "Choose your midi-file"
'Set the filter
CDBox.Filter = "Midi-files (*.mid)|*.mid"
'Show the 'Open File'-dialog
CDBox.ShowOpen
'Extract an alias from the file
Alias = Left$(CDBox.FileTitle, Len(CDBox.FileTitle) - 4) 'play midi
R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
R% = mciSendString("PLAY " + Alias + " FROM 0", 0&, 0, 0)
R% = mciSendString("CLOSE ANIMATION", 0&, 0, 0) 'play midi for 10 secs
t = Timer
Do: DoEvents: Loop Until Timer > t + PlayTime 'stop midi and close it
R% = mciSendString("OPEN " + CDBox.filename + " TYPE SEQUENCER ALIAS " + Alias, 0&, 0, 0)
R% = mciSendString&("STOP " + Alias, 0&, 0, 0)
R% = mciSendString&("CLOSE ANIMATION", 0&, 0, 0)
End Sub
Dim str1 As String
str1 = App.Path
If Right(str1, 1) <> "\" Then str1 = str1 + "\"str1 & "\sm.wav" '就可以了'这样,无论怎么用,只要文件sm.wav在当前文件夹里就行了。