新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
My.Computer.Audio.Play("SoundFile.wav")
站在用户的角度思考问题,与客户深入沟通,找到科尔沁左翼网站设计与科尔沁左翼网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、做网站、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖科尔沁左翼地区。
SoundFile.wav是你仿孙要备散链播放的声音掘碧文件的路径
左右声道控制的原理:
waveOutGetVolume取得的音量值转换成16进制,高位是左声道的值,低位是右声道的值。
’这段代码摘这段代码摘自互联网
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个自定义的函数可以方便的取得和设置左右声道。
如:
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
可答肢以用一个Slider来进行细致的控制。
下载类银亮库,可以实现左右声道的控制
方法一:调用系统DLL(这个有点不完善,也就是播放声音时窗体无法控制,效果相当于Enabled=true,但音频播放完毕后就没事了)
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的可见为False)
先添加一个windowsmediaplayer控件(工具箱里没有,需要手动添加)
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
上面的都是点击button1(按钮1)后播放声音,若是鼠标移动到某控件上发出声皮漏音的话改一下触发事件就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