示例:
- 输入声音数量从5到92
- 则音频将从audio5到audio92连续播放
- 我想中途停下来
这里我的代码:
Sub playsound()
Dim from1 As Integer
If Not Integer.TryParse(TextBox1.Text, from1) Then
Return
End If
Dim to1 As Integer
If Not Integer.TryParse(TextBox2.Text, to1) Then
Return
End If
For i As Integer = from1 To to1
Dim sound As String = "D:\Audio\audio" & i.ToString & ".wav"
Dim media As New Media.SoundPlayer(sound)
media.PlaySync()
Next
按钮播放点击:
If TextBox1.Text < 3 Then
MessageBox.Show("Audio strat from audio3")
ElseIf TextBox1.Text = "" Or TextBox2.Text = "" Then
MessageBox.Show("Can't empty")
ElseIf TextBox1.Text > 100 Or TextBox2.Text > 100 Then
MessageBox.Show("Audio finish at audio100")
ElseIf TextBox1.Text > TextBox2.Text Then
MessageBox.Show("Audio can't play backwards")
Else
Call playsound()
End If
1条答案
按热度按时间uajslkp61#
在对WinAPI函数
PlaySound()
(SoundPlayer
class正在使用)进行了***大量***试验后,我发现根本无法停止同步声音。恐怕使用SoundPlayer
类无法实现您尝试做的事情。你应该寻找其他可以用来替代
SoundPlayer
类的库,例如,你可以使用Windows Media Player,它预装在大多数Windows系统上。