사용자가 선택할 수있는 .wav 파일이 3 개 있습니다.
그런 다음 ComboBox에 입력하고 그렇게 선택했습니다.
Public ChosenSound As Object
-
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Beep" Then
ComboBox1.Text = "Beep"
ChosenSound = My.Resources.beeps
PlayBackgroundSoundResource()
End If
If ComboBox1.SelectedItem = "Chime" Then
ComboBox1.Text = "Chime"
ChosenSound = My.Resources.chime
PlayBackgroundSoundResource()
End If
If ComboBox1.SelectedItem = "Chirp" Then
ComboBox1.Text = "Chirp"
ChosenSound = My.Resources.chirp
PlayBackgroundSoundResource()
End If
End Sub
-
Sub PlayBackgroundSoundResource()
Try
My.Computer.Audio.Play(ChosenSound, AudioPlayMode.Background)
Catch ex1 As Exception
MessageBox.Show(ex1.Message)
Return
End Try
End Sub
ComboBox를 통해 선택하면 각 사운드가 완벽하게 재생되지만 다른 수단 (IE 버튼 누름)을 통해 사운드가 재생되면 다음 오류가 발생합니다.
---------------------------
---------------------------
The wave header is corrupt.
---------------------------
OK
---------------------------
버튼 누르기에 대한 코드는 다음과 같습니다.
Private Sub optionsBTNtestsound_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optionsBTNtestsound.Click
PlayBackgroundSoundResource()
End Sub
내가이 모든 것을 잘못하고 있는가? 내 사운드는 ComboBox에서 선택한 한 번만 재생되고 다른 방식으로 호출 될 때 재생되지 않는 이유는 무엇입니까?
위의 의견에서 말했듯이 스트림이 시작 부분 The wave header is corrupt
에 있지 않을 수 있으므로이 문제를 해결하려면 Audio.Play
스트림이 아직 완료되지 않았을 수 있으며 오류의 원인에 의존하지 마십시오 . 그것은 스트림과 재생 모드를 사용합니다. 왼쪽과 오른쪽 항목을 선택하면 스트림이 완료되지 않은 다음 스트림이 끝나지 않을 때 다른 파일을 재생하려고 시도합니다.
이것은 시도되고 테스트되었습니다.
Private LastFile As String = String.Empty 'Holds the last selected item
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
PlayBackgroundSoundResource(ComboBox1.SelectedItem.ToString) 'Call your method
LastFile = ComboBox1.SelectedItem.ToString.Trim 'Set your variable to the last item
End Sub
Private Sub PlayBackgroundSoundResource(ByVal strItem As String)
Dim sPlayer As New System.Media.SoundPlayer 'Create new instance of the soundplayer
Select Case strItem.Trim
Case "Beep"
sPlayer.Stream = My.Resources.beeps
Case "Chime"
sPlayer.Stream = My.Resources.chime
Case "Chirp"
sPlayer.Stream = My.Resources.chirp
End Select
sPlayer.Play() 'Play the file
If sPlayer IsNot Nothing Then sPlayer = Nothing
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PlayBackgroundSoundResource(LastFile) 'Play the last file that was selected
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다