声音代码有问题 [英] prblem withe sound code

查看:148
本文介绍了声音代码有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在按钮vb.net上添加声音的代码

我尝试了此方法,但是它不起作用
My.Computer.Audio.Play(My.Resources.Name,AudioPlayMode.Background)

i want the code for adding sound on button vb.net

i try this but it does not work
My.Computer.Audio.Play(My.Resources.Name, AudioPlayMode.Background)

推荐答案

请参阅此CodeProject文章:
Please see this CodeProject article: Play Waves in VB.NET[^].

In particular, the option of playing audio from a resource embedded in the executable (something you are probably trying to do) is explained.

—SA


尝试一下

导入System.Media

私有Sub btnPlay_Click(ByVal发送者为对象,ByVal e为EventArgs)
如果txtFileNm.Text<> String.Empty然后
昏暗的wavPlayer作为SoundPlayer =新的SoundPlayer()
wavPlayer.SoundLocation = txtFileNm.Text
AddHandler wavPlayer.LoadCompleted,AddressOf wavPlayer_LoadCompleted
wavPlayer.LoadAsync()
如果结束
结束子

私有Sub wavPlayer_LoadCompleted(ByVal发送者作为对象,ByVal e作为AsyncCompletedEventArgs)
CType(sender,System.Media.SoundPlayer).Play()
结束Sub
Try this

Imports System.Media

Private Sub btnPlay_Click(ByVal sender As Object, ByVal e As EventArgs)
If txtFileNm.Text <> String.Empty Then
Dim wavPlayer As SoundPlayer = New SoundPlayer()
wavPlayer.SoundLocation = txtFileNm.Text
AddHandler wavPlayer.LoadCompleted, AddressOf wavPlayer_LoadCompleted
wavPlayer.LoadAsync()
End If
End Sub

Private Sub wavPlayer_LoadCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
CType(sender, System.Media.SoundPlayer).Play()
End Sub


这篇关于声音代码有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆