玩酷之家

 找回密码
 立即注册
查看: 47|回复: 0

VB 使用PlaySound播放WAV声音文件的代码

[复制链接]
发表于 2021-1-8 16:38:44 | 显示全部楼层 |阅读模式
方法很简单。不过首先要声明函数和基本常数。用PlaySound虽然简单,但也有其局限性,如果文件稍大,就不能采用这种方式了。此时需要采用DirectSound,当然其调用方式也复杂一些。

  1. Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  2. Private Const SND_ASYNC = &H1 ' play asynchronously
  3. Private Const SND_FILENAME = &H20000 ' name is a file name
  4. Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound

  5. Private Sub Form_Load()
  6. PlaySound App.Path & "\News.wav", 0, SND_FILENAME Or SND_ASYNC
  7. End Sub
复制代码


如果需要使其循环播放,可使用:PlaySound App.Path &  "\News.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_LOOP

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|玩酷之家 ( 鄂ICP备14012049号 )

GMT+8, 2021-1-21 03:27 , Processed in 1.092002 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表