2017-04-21 173 views
0

例如:聲音如何停止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 
+0

我已經更新了我的答案。 –

回答

0

試驗很多與WinAPI的功能PlaySound()(其中SoundPlayer class使用)之後,我發現,這是根本不可能停同步聲音。恐怕你正在嘗試做的事情是不可能的,使用SoundPlayer課程。

你應該看看其他庫,你可以用它來代替SoundPlayer類。例如,您可以使用預裝在大多數Windows系統上的Windows Media Player

+0

那麼它不能連續播放和循環將是無用的? –

+0

@HazuKeil:對不起,我誤解了你的問題。我編輯了答案。 –

+0

我找不到TaskCreationOptions.DenyChildAttach,該選項是AttachedToParent,LongRunning,None,PreferFairness。現在可以點擊停止按鈕,但聲音不會停止。 –

相關問題