This project has moved. For the latest updates, please go here.

How to display the current time?

Jan 10, 2011 at 1:02 PM

I use the following method do play a MP3 file:


 public void play_PreviewContactDown(object sender, ContactEventArgs e)
            (sender as SurfaceButton).IsEnabled = false;
            ((sender as SurfaceButton).Tag as SurfaceButton).IsEnabled = true;
            waveOutDevice = new WasapiOut(AudioClientShareMode.Shared, 100);
            mainOutputStream = CreateInputStream( ((sender as SurfaceButton).Content as Polygon).Tag as String);


Now, I'd like to display the current time of the playback in a textview. But how can I get it? I know that using mainOutputStream.CurrentTime will display the current time of the stream, but how can I update the current time during the whole playback ofa file?

Jan 10, 2011 at 1:16 PM

just use a timer to update the time every half second. Have a look at the NAudio demo app to see this in action


Jan 10, 2011 at 1:21 PM

Yes I examined the demo app, but there is Timer#tick used. This isn't available in my timer.

Jan 10, 2011 at 1:33 PM

are you using Windows Forms or WPF?

Jan 10, 2011 at 2:00 PM

I'm using WPF. Now i found out that i have to use Timer#Elapsed instead of Timer#Tick.


However, one problem is left. I use this code to detect if the playback is finshed:


waveOutDevice.PlaybackStopped+=new EventHandler(waveOutDevice_PlaybackStopped);

private void waveOutDevice_PlaybackStopped(object sender, EventArgs e)
But the method waveOUtDevice_PlaybackStopped is nevercalled and thats why the timer isn't stop and always updates current time.

Jan 10, 2011 at 4:19 PM

Playback will only stop of its own accord if the source WaveProvider stops returning data. That isn't always the case with all the WaveProviders/WaveStreams in your input chain. NAudio demo just detects if the position has gone past the length and stops manually.