My.Computer.Audio.Play("SoundFile.wav")
站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到科爾沁左翼網(wǎng)站設(shè)計(jì)與科爾沁左翼網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、網(wǎng)頁(yè)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋科爾沁左翼地區(qū)。
SoundFile.wav是你仿孫要備散鏈播放的聲音掘碧文件的路徑
左右聲道控制的原理:
waveOutGetVolume取得的音量值轉(zhuǎn)換成16進(jìn)制,高位是左聲道的值,低位是右聲道的值。
’這段代碼摘這段代碼摘自互聯(lián)網(wǎng)
Private Declare Function waveOutGetVolume Lib "winmm.dll"鋒舉寬 (ByVal uDeviceID As Long, lpdwVolume As Long) As Long
Private Declare Function waveOutSetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, ByVal dwVolume As Long) As Long
Const WAVE_MAPPER = -1
Public Function SetLR(ByVal L As Long, ByVal R As Long) As Long
Dim mLR As String
mLR = "H" Right("0000" Hex(L), 4) Right("0000" Hex(R), 4)
waveOutSetVolume WAVE_MAPPER, CLng(mLR)
End Function
Public Function GetLR(ByRef L As Long, ByRef R As Long) As Long
Dim LR As Long
waveOutGetVolume WAVE_MAPPER, LR
L = CLng("H" Left(Hex(LR), 4))
R = CLng("H" Right(Hex(LR), 4))
End Function
以上2個(gè)自定義的函數(shù)可以方便的取得和設(shè)置左右聲道。
如:
Private Sub Form_Load()
Dim mL As Long, mR As Long
GetLR mL, mR
MsgBox "左" mL "--右" mR
End Sub
Private Sub Command1_Click()
SetLR 65535, 22222
End Sub
可答肢以用一個(gè)Slider來(lái)進(jìn)行細(xì)致的控制。
下載類銀亮庫(kù),可以實(shí)現(xiàn)左右聲道的控制
方法一:調(diào)用系統(tǒng)DLL(這個(gè)有點(diǎn)不完善,也就是播放聲音時(shí)窗體無(wú)法控制,效果相當(dāng)于Enabled=true,但音頻播放完畢后就沒(méi)事了)
Private?Declare?Function?sndPlaySound?Lib?"Winmm.dll"?Alias?"sndPlaySoundA"?渣瞎(ByVal?lpszSoundName?As?String,?ByVal?uFlags?As?Long)?As?Long
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Dim?SoundFile?As?String,?Result?As?Long
SoundFile?=?"D:\KuGou\Pianoboy?-?如握空第105天.wav"?'此處為路徑
Result?=?sndPlaySound(SoundFile,?0)
End?Sub
方法二:使用WindowsMediaPlayer(WindowsMediaPlayer1的可見(jiàn)為False)
先添加一個(gè)windowsmediaplayer控件(工具箱里沒(méi)有,需要手動(dòng)添加)
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
WindowsMediaPlayer1.visible=False
Me.WindowsMediaPlayer1.URL?=?"D:\KuGou\Pianoboy?-?第105天.mp3"
End?Sub
上面的都是點(diǎn)擊button1(按鈕1)后播放聲音,若是鼠標(biāo)移動(dòng)到某控件上發(fā)出聲皮漏音的話改一下觸發(fā)事件就OK了。
Imports?System.Runtime.InteropServices
Public?Class?Form1
Private?mute?As?Integer?=?H80000
Private?up?As?Integer?=?HA0000
Private?down?As?Integer?=?H90000
Private?WM_APPCOMMAND?橡賀As?Integer?=?H319
廳如頃DllImport("user32.dll")?_
Public?Shared?Function?SendMessageW(hWnd?As?IntPtr,?Msg?As?Integer,?wParam?As?IntPtr,?lParam?As?IntPtr)?As?IntPtr
End?Function
'加大
Private?Sub?btnUp_Click(sender?As?System.Object,?e?As?System.EventArgs)?Handles?btnUp.Click
SendMessageW(Me.Handle,?WM_APPCOMMAND,?Me.Handle,?New?IntPtr(up))
End?Sub
扮陸??'減小
Private?Sub?btnZero_Click(sender?As?System.Object,?e?As?System.EventArgs)?Handles?btnZero.Click
SendMessageW(Me.Handle,?WM_APPCOMMAND,?Me.Handle,?New?IntPtr(mute))
End?Sub
'靜音
Private?Sub?btnDown_Click(sender?As?System.Object,?e?As?System.EventArgs)?Handles?btnDown.Click
SendMessageW(Me.Handle,?WM_APPCOMMAND,?Me.Handle,?New?IntPtr(down))
End?Sub
End?Class