What you search for, is an event that fires On playback position change. I use this code to raise a change when each sample is read:
'Declare on top:
Public WithEvents notify as NotifyingSampleProvider = Nothing
Public mp3Reader As Mp3FileReader = Nothing
'In your playback code:
Public Sub Play_Sound(songname As String)
mp3Reader = New Mp3FileReader(songname)
notify = New NotifyingSampleProvider(mp3Reader.ToSampleProvider)
If waveOut.PlaybackState = PlaybackState.Playing Then
waveOut.Stop()
mp3Reader.Close()
Else
waveOut.Init(Notify)
waveOut.Play()
End If
End Sub
'Use the notify event to update your playback position with each processed sample.
'This Event is the most accurate and fires at your Mp3FileReader´s samplerate (usually 44100 times per second).
'For performance reasons you should better count for some samples till update,
'or your Form will redraw the labels 44100 times per second (overkill cpu waste)
Private SampleCounter as Integer = 0
Private Sub notify_Sample(ByVal sender As Object, ByVal e As NAudio.Wave.SampleEventArgs)
SampleCounter += 1
'For example wait 1024 samples till updating again.
if SampleCounter >= 1024 then
SampleCounter = 0
'Current time:
CurrentLenLabel.Text = New DateTime(mp3Reader.CurrentTime.Ticks).ToString("HH:mm:ss")
'Total time:
TotalLenLabel.Text = New DateTime(mp3Reader.TotalTime.Ticks).ToString("HH:mm:ss")
End If
End Sub