展开全部
不用ActiveX控件也能播放声音文件
讲一下代码保存至module
Option Explicit
Public Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
接下来把下面的代码粘贴到你想播放声音文件的地方,比如放在命令按钮的Click事件中
Dim sFlags As Long
sFlags = SND_ASYNC Or SND_NODEFAULT
sndPlaySound "FileName.Wav", sFlags
把上面的FileName.Wav换成你想要播放的声音文件的完整路径及文件名就行了。
如果你仅仅是想播放一些Windows常用的声音,比如说退出Windows的声音,有一种更简单的写法
sndPlaySound "SystemExit",sFlags
将SystemExit换成下面这些参数,试试是什么声音?
SystemStart
SystemExit
SystemDefault
SystemQuestion
SystemAsterisk
SystemExclamation
SystemHand
下面是sFlags所用参数的说明:
参数 说明
SND_SYNC Plays the WAV file specified and returns only when the sound has stopped playing
SND_ASYNC Plays the WAV file an continues after the sound has started playing.
SND_NODEFAULT Do not play the default sound if the if the WAV file is not found.
SND_LOOP Plays the WAV file continuously until sndPlaySound is called again. Remember to put SND_ASYNC in the sFlag variable as well. Else your application will lock-up. To stop playing the wave file set the "FileName.Wav" to Null instead.
SND_NOSTOP Return to the beginning of the WAV file if it's already playing.
讲一下代码保存至module
Option Explicit
Public Declare Function sndPlaySound Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Const SND_LOOP = &H8
Const SND_NOSTOP = &H10
接下来把下面的代码粘贴到你想播放声音文件的地方,比如放在命令按钮的Click事件中
Dim sFlags As Long
sFlags = SND_ASYNC Or SND_NODEFAULT
sndPlaySound "FileName.Wav", sFlags
把上面的FileName.Wav换成你想要播放的声音文件的完整路径及文件名就行了。
如果你仅仅是想播放一些Windows常用的声音,比如说退出Windows的声音,有一种更简单的写法
sndPlaySound "SystemExit",sFlags
将SystemExit换成下面这些参数,试试是什么声音?
SystemStart
SystemExit
SystemDefault
SystemQuestion
SystemAsterisk
SystemExclamation
SystemHand
下面是sFlags所用参数的说明:
参数 说明
SND_SYNC Plays the WAV file specified and returns only when the sound has stopped playing
SND_ASYNC Plays the WAV file an continues after the sound has started playing.
SND_NODEFAULT Do not play the default sound if the if the WAV file is not found.
SND_LOOP Plays the WAV file continuously until sndPlaySound is called again. Remember to put SND_ASYNC in the sFlag variable as well. Else your application will lock-up. To stop playing the wave file set the "FileName.Wav" to Null instead.
SND_NOSTOP Return to the beginning of the WAV file if it's already playing.
展开全部
添加一个WindowsMediaPlayer控件,播放的语句:
WindowsMediaPlayer1.URL = "音频文件路径"
跟windowsmediaplayer一样,有停,放
WindowsMediaPlayer1.URL = "音频文件路径"
跟windowsmediaplayer一样,有停,放
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把音乐mp3文件和exe文件放在同一个目录下,假设是1.mp3,加入如下代码设置音乐文件路径:
windowsmediaplayer1.url
=
app.path
&
"\1.mp3"
即可解决问题,不过音乐文件要和exe在一起。
如果要做到只有exe文件还可以使用资源文件的方式,程序运行的时候释放资源。
windowsmediaplayer1.url
=
app.path
&
"\1.mp3"
即可解决问题,不过音乐文件要和exe在一起。
如果要做到只有exe文件还可以使用资源文件的方式,程序运行的时候释放资源。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询