vb 播放音乐的问题? 急啊!

kingvictor 2003-05-11 01:12:34
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" 是不行的?
请教各位高手!
...全文
34 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
SmileSkyNet 2003-05-11
app.path不是你的声音文件的目录,而是exe文件的目录,如果你的声音文件不在同一目录下用app.path当然是不行的了
回复
csdngoodnight 2003-05-11
其实就是相对路径
Dim str1 As String
str1 = App.Path
If Right(str1, 1) <> "\" Then str1 = str1 + "\"

str1 & "\sm.wav" '就可以了

'这样,无论怎么用,只要文件sm.wav在当前文件夹里就行了。
回复
lihonggen0 2003-05-11
R% = mciSendString&("OPEN " + app.path + "\sm.wav" + " TYPE waveaudio ALIAS NN", 0&, 0, 0)
回复
lihonggen0 2003-05-11
R% = mciSendString&("OPEN " + app.path + "\sm.wav" + "TYPE waveaudio ALIAS NN", 0&, 0, 0)
回复
lihonggen0 2003-05-11
看一下这个:

'This project needs a Common Dialog box, named 'CDBox'
' (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
回复
cow8063 2003-05-11
C:\multi_files\vb\把这个用变量代替不就得了
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-11 01:12
社区公告
暂无公告