这种音频去到网上下,网上有,自己用录音机录也行
然后调用API播放就可以了
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
'Play Msg.wav
Call sndPlaySound("Msg.wav", &H1 Or &H2 Or &H8)'这里的msg.wav必须已添加在资源管理器中
'Stop
Call sndPlaySound(0, 0)
————————————————
如果是mp3格式,用这段代码
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Dim path$
Private Sub Form_Load()
path = "C:\1.mp3" '设置路径
Timer1.Interval = 200
Timer1.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
mciSendString "close all", 0, 0, 0
End Sub
Private Sub Timer1_Timer()
Dim buffer As String * 128
Dim pos As Integer
mciSendString "status " &path &" mode", buffer, 128, 0&
If Left(buffer, 7) = "stopped" Then
mciSendString "close all", 0, 0, 0
mciSendString "open " &path, 0, 0, 0
mciSendString "play " &path, 0, 0, 0
End If
End Sub
上面的路径可以用APP.PATH返回
当然也就不用添加到资源管理器中了
QQ304728539
//给你个例子import java.io.*
import javax.sound.sampled.*
import javax.swing.*
import java.awt.event.*
public class Au extends JFrame
{
public static void main(String[] args)
{
Au w=new Au()
}
Au()
{
JButton b=new JButton("播放")
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
play()
}
})
add(b)
setResizable(false)
pack()
setLocationRelativeTo(null)
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
setVisible(true)
}
void play()
{
//将f指定为声音文件的文件名,
//声音文件只能是WAVE、AU、AIFF、AIFC、SND格式的。
final String f="s.wav"
Clip c=null
try
{
c=AudioSystem.getClip()
c.open(AudioSystem.getAudioInputStream(new File(f)))
c.loop(0)
}
catch(Exception ex)
{
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)