如何停止PlaySync在声音播放按钮点击
- 输入数量从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
BtnPlay点击:
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
试验很多与WinAPI的功能PlaySound()
(其中SoundPlayer
class使用)之后,我发现,这是根本不可能停同步声音。恐怕你正在尝试做的事情是不可能的,使用SoundPlayer
课程。
你应该看看其他库,你可以用它来代替SoundPlayer
类。例如,您可以使用预装在大多数Windows系统上的Windows Media Player。
那么它不能连续播放和循环将是无用的? –
@HazuKeil:对不起,我误解了你的问题。我编辑了答案。 –
我找不到TaskCreationOptions.DenyChildAttach,该选项是AttachedToParent,LongRunning,None,PreferFairness。现在可以点击停止按钮,但声音不会停止。 –
我已经更新了我的答案。 –