VB.net 如何同时播放多个资源文件内的wav用API mciSendString可以同时播放多个声音,需要提供路径 。
资源文件很麻烦,要用反射读取出来,再用IO写到磁盘路径 。
你是做游戏把?软糖建议是不要使用资源文件 , 而使用本地文件 。
用个BGM文件夹保存背景音乐,用SE文件夹保存音效(学习RPG Maker的做法)
API代码奉上,具体实现模块字数超过最大值,请下载附件
Imports System.Text
''' summary
''' 可播放MPEG,AVI,WAV,MP3,MID,WMA等格式的音频文件,*不支持OGG
''' /summary
Public Class 音频设备
'声明API函数: mciSendString
System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint:="mciSendString")
Public Shared Function mciSendString(strCommand As String,
strReturn As StringBuilder,
iReturnLength As Integer,
hwndCallback As Integer) As Integer
End Function
'声明API函数: mciGetErrorString
System.Runtime.InteropServices.DllImport("winmm.dll", EntryPoint:="mciSendString")
Public Shared Function mciGetErrorString(errCode As Integer,
errMsg As StringBuilder,
buflen As Integer) As Integer
调用方法
Public Class Form1
Dim 音频设备 As New 音频设备
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim 路径 = "F:\音乐文件名.mp3"
音频设备.打开("自定义名称1", 路径)
音频设备.播放("自定义名称1")
'音频设备.暂停("自定义名称1")
'音频设备.继续("自定义名称1")
'音频设备.关闭("自定义名称1")
End Sub
End Class
如满意 , 请采纳 , 还有不懂的请追问,谢谢 。
VB.net如何加载音效?方法一:调用系统DLL(这个有点不完善vbnet播放声音,也就是播放声音时窗体无法控制,效果相当于Enabled=true,但音频播放完毕后就没事vbnet播放声音了)
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了 。
VB.NET中播放背景音乐最简单的办法是什么啊?给你我的程序,自己研究一下吧,我也不是很明白 。
Public Class Form1
Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
Const SND_filename As Integer = H20000
Const SND_alias As Integer = H10000
Const SND_sync As Integer = H0
Declare Auto Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Integer
Declare Auto Function sndPlaySound Lib "winmm.dll" (ByVal filename As String, ByVal options As Integer) As Integer
Private Const SND_memory As Integer = H4
Private Const SND_async As Integer = H1
Private Const proess_domain As String = ""
Const SND_sync1 = H0
Const SND_async1 = H1
Const SND_nodefault = H2
Const SND_loop = H8
Const SND_nostop = H10
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Beep()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFileName As String = "start.wav"
PlaySound(strFileName, 0, SND_filename)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
PlaySound("systemstart", 0, SND_alias Or SND_sync)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim ret As Long
Dim strfilename As String
strfilename = "start.wav"
ret = sndPlaySound(strfilename.ToCharArray, 0)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim i As Integer
i = waveOutGetNumDevs()
If i0 Then
MsgBox("可以播放声音", 64, "检测")
Else
MsgBox("不能播放声音", 64, "检测")
End If
End Sub
End Class
我用二进制读取了声音文件,VB或VB.net如何播放二进制声音数据,请高手赐教!不明白你为什么要二进制读取声音文件,VB可以直接调用API播放声音文件 , 不需要你二进制来读取声音文件的 。
Private
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA"
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub PlayWavFile(strFileName As String, PlayCount As Long, JianGe As Long)
'strFileName 要播放的文件名(带路径)
'playCount 播放的次数
'JianGe多次播放时,每次的时间间隔
If Len(Dir(strFileName)) = 0 Then Exit Sub
If PlayCount = 0 Then Exit Sub
If JianGe1000 Then JianGe = 1000
DoEvents
sndPlaySound strFileName, 161
Sleep JianGe
Call PlayWavFile(strFileName, PlayCount - 1, JianGe)
End Sub
Private Sub Form_Click()
PlayWavFile "C:\aaa.wav", 1, 1000 '参数:播放文件,播放次数,播放间隔
End Sub
vb.net 中 如何实现 播放mp3文件在.NET里,没有托管vbnet播放声音的音乐播放器,用API只能播放WAV格式,对于MP3等形式的音频文件,就要依赖于其vbnet播放声音他控件了 , 常用的就是
MediaPlayer 。使用方法:
在工具箱上点右键 , 选择“选择项目(Choose Items)”,切到COM选项卡,找到 Windows Media Player, 勾选 , 确定
在t工具箱上 , 把刚才加入的MediaPlayer控件,拖放到窗体上
代码:
WindowsMediaPlayer1.URL = "mp3文件路径,支持网络路径"
WindowsMediaPlayer1.Ctlcontrols.play
基本就OK了,至于其他的操作诸如下一曲上一曲暂停停止,直接看 WindowsMediaPlayer1.Ctlcontrols. 里面的方法吧 。
VB.NET如何调用并播放项目资源内的WAV文件 。代码是没有错vbnet播放声音的vbnet播放声音,但是其中关键是声音文件资源定义字串必须使用根命名空间vbnet播放声音,不能用程序集名称vbnet播放声音;还有就是声音文件必须选属性为嵌入资源 。
My.Computer.Audio.Play(My.Resources.xxxmusic1xxx, AudioPlayMode.Background)
【vbnet播放声音 vb 播放mp3】vbnet播放声音的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb 播放mp3、vbnet播放声音的信息别忘了在本站进行查找喔 。
推荐阅读
- 苹果六plus有ios14吗,苹果6sp有ios14吗
- 苹果手机丢了怎么锁定,苹果手机丢了怎么锁定手机
- 农场像素经营游戏,像素 农场
- linux更改网段命令 linux更改网络地址
- oracle表按实际大小分配空间,oracle 按大小排序
- 什么是css中的标签选择器,css中标签选择器的写法是
- 电脑买到坏显卡怎么赔偿,坏的显卡还能卖吗
- vb.net创建表 vbnet createobject
- 电脑上怎么看显卡,电脑上怎么看显卡出厂日期