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" 是不行的?
请教各位高手!
...全文
79 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
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\把这个用变量代替不就得了

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧