Advertisement
TheVideoVolcano

Naudio playsound

May 13th, 2013
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.07 KB | None | 0 0
  1. 'Naudio.NET playsound method
  2. 'By TheVideoVolcano and JulioNIB
  3.  
  4.   Private Sub PlaySound(ByVal soundfilelocation As String)
  5.         Dim reader As NAudio.Wave.WaveFileReader = New NAudio.Wave.WaveFileReader(soundfilelocation)
  6.         Dim wavechannel As NAudio.Wave.WaveChannel32 = New NAudio.Wave.WaveChannel32(reader)
  7.         Dim player As NAudio.Wave.DirectSoundOut = New NAudio.Wave.DirectSoundOut
  8.         Try
  9.             player.Init(wavechannel)
  10.             If Exists(soundfilelocation) Then
  11.                 player.Play()
  12.            end if
  13.            
  14.  
  15.             player.Dispose()
  16.         Catch
  17.         End Try
  18.     End Sub
  19.  
  20. '---------------------------------------------------------------------------------------------------
  21.  
  22. 'use like this
  23.  
  24. PlaySound("C:\file.wav", true)
  25.  
  26. '---------------------------------------------------------------------------------------------------
  27.  
  28. '--Extras--
  29.  
  30. wavechannel.skip(1) 'skip 1 second into the .wav file
  31. player.stop 'stops sound
  32. player.volume = 1 '1 is default 0.5 is half
  33.  
  34. 'See more on the documentation at Naudio's site.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement