First question about volume was answered by Mark - Volume is in the range 0.0 <= volume <= 1.0
, so setting the volume to 2.0 is invalid.
As to how to use MP3 files...
You can replace the WaveFileReader
with Mp3FileReader
in your code if the data you are feeding in is MP3 instead of WAV. If the data is always coming from a file you could use new AudioFileReader(filename)
instead and let it work out what the compression format is.
Here's your code with MP3 instead of WAV:
Public Volume as Single = 0.01
Dim Wave1 As New NAudio.Wave.WaveOut
Dim xa() As Byte = IO.File.ReadAllBytes("C:\Song - Come Out and Play.mp3")
Sub PlaySound()
Dim data As New IO.MemoryStream(xa)
Wave1.Init( _
New NAudio.Wave.BlockAlignReductionStream( _
NAudio.Wave.WaveFormatConversionStream.CreatePcmStream( _
New NAudio.Wave.Mp3FileReader(data) _
)))
Wave1.Volume = Volume
Wave1.Play()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PlaySound()
End Sub