Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: Playing WMA

$
0
0

First off I just found this library and I love it. I have been able to play WAV and MP3 with no problem. However when I try to play WMA nothing happens even though when debugging it reports the state is still playing. So if you could possibly point out my problem it would be great. Here is my code, sorry it is in Vb...

    Sub Main()
        Dim waveoutdevice As IWavePlayer
        Dim mainoutputstream As WaveStream
        waveoutdevice = New WasapiOut(AudioClientShareMode.Shared, 100)
        mainoutputstream = CreateInputStream("\Test.wma")
        waveoutdevice.Init(mainoutputstream)
        waveoutdevice.Play()
        Do While waveoutdevice.PlaybackState <> PlaybackState.Stopped
            Threading.Thread.Sleep(100)
        Loop
        waveoutdevice.Dispose()
        mainoutputstream.Dispose()
    End Sub
    Private Function CreateInputStream(ByVal fileName As String) As WaveStream
        Dim inputStream As WaveChannel32

        If fileName.EndsWith(".mp3") Then
            Dim mp3Reader As WaveStream = New Mp3FileReader(fileName)
            inputStream = New WaveChannel32(mp3Reader)
        ElseIf fileName.EndsWith(".wav") Then
            Dim wavreader As WaveStream = New WaveFileReader(fileName)
            inputStream = New WaveChannel32(wavreader)
        ElseIf fileName.EndsWith(".wma") Then
            Dim wavreader As WaveStream = New WMAFileReader(fileName)
            inputStream = New WaveChannel32(wavreader)
        Else
            Throw New InvalidOperationException("Unsupported extension")
        End If
        Return inputStream
    End Function


Viewing all articles
Browse latest Browse all 5831

Trending Articles