Vb.net 如何在单击按钮时停止SoundPlayer中的播放同步
例如:Vb.net 如何在单击按钮时停止SoundPlayer中的播放同步,vb.net,winforms,loops,synchronization,Vb.net,Winforms,Loops,Synchronization,例如: 从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
- 从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
BTN显示单击:
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
如果TextBox1.Text<3,则
MessageBox.Show(“来自audio3的音频层”)
ElseIf TextBox1.Text=“”或TextBox2.Text=“”然后
MessageBox.Show(“不能为空”)
ElseIf TextBox1.Text>100或TextBox2.Text>100然后
MessageBox.Show(“audio100音频结束”)
ElseIf TextBox1.Text>TextBox2.Text然后
MessageBox.Show(“音频不能向后播放”)
其他的
调用playsound()
如果结束
在对WinAPI函数(正在使用)进行了大量试验后,我发现根本不可能停止同步声音。恐怕您在使用SoundPlayer
类时不可能做到这一点
您应该查看可以用作
SoundPlayer
类替代品的其他库。例如,你可以使用,它预装在大多数Windows系统上。这样它就不能连续播放,循环也没用了?@HazuKeil:对不起,我误解了你的问题。我已编辑了答案。我找不到TaskCreationOptions.DenyChildatach,该选项已附加到副本、长时间运行、无、优先公平。现在可以单击“停止”按钮,但声音没有停止。@HazuKeil:使用TaskCreationOptions。然后无。请查看我答案的编辑。我已经按照您的指示进行了操作,但仍然无法停止。我已经更新了我的答案。