45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:使用DirectSound播放WAV的方法

使用DirectSound播放WAV的方法

2016-09-06 18:26:20 来源:www.45fan.com 【

使用DirectSound播放WAV的方法

Imports DxVBLib

Public Class DirectSound
Dim dx As New DxVBLib.DirectX7
Dim ds As DxVBLib.DirectSound

Dim Buf As DxVBLib.DirectSoundBuffer '创建缓冲
Dim waveformatex As Object
Dim sdbuffer As DxVBLib.DSBUFFERDESC
Dim wvformat As DxVBLib.WAVEFORMATEX

Dim mHwnd As IntPtr

Public Sub New(ByVal hwnd As IntPtr)
mHwnd = hwnd
ds = dx.DirectSoundCreate("")
End Sub

Public Sub Play()
Call ds.SetCooperativeLevel(mHwnd, DxVBLib.CONST_DSSCLFLAGS.DSSCL_PRIORITY)

sdbuffer.lFlags = CONST_DSBCAPSFLAGS.DSBCAPS_STICKYFOCUS

Dim wave As String = "waveformatex"

wvformat.nSize = wave.Length
wvformat.nChannels = 1
wvformat.lSamplesPerSec = 1000 ' 44100
wvformat.nBitsPerSample = 16
wvformat.nBlockAlign = wvformat.nBitsPerSample / 8 * wvformat.nChannels
wvformat.lAvgBytesPerSec = wvformat.lSamplesPerSec * wvformat.nBlockAlign * 10

'音声をバッファに貯める
Buf = ds.CreateSoundBufferFromFile("c:/风之彩 钢琴曲.wav", sdbuffer, wvformat)
'ここに可変のwaitを入れたいのです。

'再生
Call Buf.Play(CONST_DSBPLAYFLAGS.DSBPLAY_LOOPING)
'再生終了するまで次の処理には行かない。
Do While Buf.GetStatus = CONST_DSBSTATUSFLAGS.DSBSTATUS_PLAYING
Application.DoEvents()
Loop
End Sub
End Class

 

本文地址:http://www.45fan.com/a/question/73335.html
Tags: 播放 DirectSound WAV
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部