Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27189

Sound doesn't play instantly...but wait for next operation to complete!

$
0
0
I've a big interrogation concerning sound playback (WMP.lib)!
This code should play a sound, then compute...but it computes then play the sound!

Code:

Class MainWindow
    Dim writingPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\_UI Sounds\"
    Dim uiPlayer As New WMPLib.WindowsMediaPlayer
    Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        RunTest()
    End Sub
    Private Sub RunTest()
        Debug.Print("Started!")
        uiPlayer.URL = writingPath & "son1.wav"
        uiPlayer.controls.play()
        '
        Dim a As Integer = 0
        For i As Integer = 0 To 999999999
            a = i
        Next
        Debug.Print("Done!")
    End Sub
End Class

I thought that I perhaps should run the sound in a thread to be sure that it's played by its own!?
But this gives the same result

Code:

Imports System.Threading
Class MainWindow
    Dim writingPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\_UI Sounds\"
    Dim uiPlayer As New WMPLib.WindowsMediaPlayer
    Dim uiThread As Thread = New Thread(AddressOf PlayFile)
    Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        RunTest()
    End Sub
    Private Sub RunTest()
        uiThread = New Thread(AddressOf PlayFile)
        uiThread.Start()
        '
        Debug.Print("Started!")
        Dim a As Integer = 0
        For i As Integer = 0 To 999999999
            a = i
        Next
        Debug.Print("Done!")
    End Sub
    Private Sub PlayFile()
        uiPlayer.URL = writingPath & "son1.wav"
        uiPlayer.controls.play()
    End Sub
End Class

How should I please proceed to hear my sound 'instantly'?
What's my mistake?

Thanks for your help!!

Viewing all articles
Browse latest Browse all 27189

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>