VB_如何将声音文件加载到内存后再播放.
想做个类似电子琴的东西,按一个按键即刻发出一种声音.如果当按下按键时再用wmp控件从硬盘读取播放的话,会太慢.怎么才能将声音文件先全部加载到内存中,按下按钮时马上播放出来...
想做个类似电子琴的东西,按一个按键即刻发出一种声音.
如果当按下按键时再用wmp控件从硬盘读取播放的话,会太慢.
怎么才能将声音文件先全部加载到内存中,按下按钮时马上播放出来呢?
谢谢. 展开
如果当按下按键时再用wmp控件从硬盘读取播放的话,会太慢.
怎么才能将声音文件先全部加载到内存中,按下按钮时马上播放出来呢?
谢谢. 展开
3个回答
展开全部
Option Explicit
Private Declare Function PlaySoundData Lib "winmm.dll" Alias "PlaySoundA" (lpData As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1 '异步播放,否则就独占播放
Private Const SND_NODEFAULT = &H2 '不使用缺省声音
Private Const SND_MEMORY = &H4 '指向一个内存文件
Private Const SND_FILENAME = &H20000 '指向一个实际文件
Private Const SND_LOOP = &H8 '循环播放
Private Const SND_ALIAS_START = 0 '结束播放
Dim m_snd() As Byte
Private Sub Command1_Click()
PlaySoundData m_snd(0), 0, SND_MEMORY Or SND_ASYNC Or SND_NODEFAULT
End Sub
Private Sub Form_Load()
m_snd = LoadResData(102, "CUSTOM") '在资源管理中加载WAV自定义文件
End Sub
Private Declare Function PlaySoundData Lib "winmm.dll" Alias "PlaySoundA" (lpData As Any, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1 '异步播放,否则就独占播放
Private Const SND_NODEFAULT = &H2 '不使用缺省声音
Private Const SND_MEMORY = &H4 '指向一个内存文件
Private Const SND_FILENAME = &H20000 '指向一个实际文件
Private Const SND_LOOP = &H8 '循环播放
Private Const SND_ALIAS_START = 0 '结束播放
Dim m_snd() As Byte
Private Sub Command1_Click()
PlaySoundData m_snd(0), 0, SND_MEMORY Or SND_ASYNC Or SND_NODEFAULT
End Sub
Private Sub Form_Load()
m_snd = LoadResData(102, "CUSTOM") '在资源管理中加载WAV自定义文件
End Sub
展开全部
1楼你的方法也不完美,因为楼主要做电子琴一样的东西,你那个只有等播放完之后才能播放下一个声音,我的方法不需要等声音放完就能直接播放下一个声音
Private Const SND_ASYNC = &H1
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub Command1_Click()
sndPlaySound "路径", SND_ASYNC
End Sub
Private Const SND_ASYNC = &H1
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub Command1_Click()
sndPlaySound "路径", SND_ASYNC
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用api播放wav声音.wmp用于播放声音绝对是一个错误..
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000
Private Sub Command1_Click()
PlaySound "wav路径", 0, SND_FILENAME Or SND_SYNC
End Sub
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000
Private Sub Command1_Click()
PlaySound "wav路径", 0, SND_FILENAME Or SND_SYNC
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询