VB.net如何加载音效?方法一vb.net控制声音:调用系统DLL(这个有点不完善vb.net控制声音,也就是播放声音时窗体无法控制,效果相当于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(WindowsMediaPlayer1vb.net控制声音的可见为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了 。
vb.net中如何播放声音,是要什么控件嘛?My.Computer.Audio.Play("SoundFile.wav")
SoundFile.wav是vb.net控制声音你要播放vb.net控制声音的声音文件vb.net控制声音的路径
vb.net控制系统音量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
vb.net设置音量调用系统Api
[DllImport("winmm.dll")]//引用winmm.dll
publicstaticexternlongwaveOutSetVolume(longdeviceID,longVolume);
在winmm.dll中
第一个参数可以为0vb.net控制声音 , 表示首选设备
第二个参数为音量:0xFFFF为最大vb.net控制声音,0x0000为最?。?其中高位(前两位)表示右声道音量 , 低位(后两位)表示左 声道音量。
2、弹出系统音量调节框
ProcessStartInfo Info=new ProcessStartInfo();
Info.FileName = "Sndvol32";
Process.Start(Info);
vb.net声道控制左右声道控制的原理:
waveOutGetVolume取得的音量值转换成16进制,高位是左声道的值,低位是右声道的值 。
’这段代码摘这段代码摘自互联网
PrivateDeclareFunctionwaveOutGetVolumeLib"winmm.dll"(ByValuDeviceIDAsLong,lpdwVolumeAsLong)AsLong
PrivateDeclareFunctionwaveOutSetVolumeLib"winmm.dll"(ByValuDeviceIDAsLong,ByValdwVolumeAsLong)AsLong
ConstWAVE_MAPPER=-1
PublicFunctionSetLR(ByValLAsLong,ByValRAsLong)AsLong
DimmLRAsString
mLR="H"Right("0000"Hex(L),4)Right("0000"Hex(R),4)
waveOutSetVolumeWAVE_MAPPER,CLng(mLR)
EndFunction
PublicFunctionGetLR(ByRefLAsLong,ByRefRAsLong)AsLong
DimLRAsLong
waveOutGetVolumeWAVE_MAPPER,LR
L=CLng("H"Left(Hex(LR),4))
R=CLng("H"Right(Hex(LR),4))
EndFunction
以上2个自定义的函数可以方便的取得和设置左右声道 。
推荐阅读
- 七台河易货平台招代理商,七台河物流配货电话
- 什么是横滚拍摄,横滚跟随用来拍什么
- 销售营销如何布局,什么是销售布局
- erp系统功能概述怎么写好,erp系统功能结构图
- mysql怎么统计行数的简单介绍
- hbase最核心的模块,hbase的核心数据结构是什么
- 键盘输入数字给js当数据,js从键盘输入一个数
- go语言二维数组赋值 go语言数组转字符串
- 买4k电视需要什么条件,4k电视到底值得购买吗