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

New Post: WPF Dispatcher Timer issue

$
0
0

Hi All,

 

Thanks for making this powerfull library avaiable.

I am a newbee in C#, but I gave myself the challange to learn wpf more by trying to convert Audio Playback demo. I succeed by being able to select the output driver model and select the output and then play-pause-stop a file, volume is ok as well. I used the Dispatcher Timer for the elapsed seconds label control and the slider. They work very well but I am hearing a kind of "tick" at my time intervals when I play a MP3. I thought this was heavy work for the dispatcher timer and try to use System.Timers. However since this is a different thread then the gui, I am stuck here reading through google for hours but still could not find a way to change my tick event below for the Gui to be invoked; Can you please help?

private void TickTimer()
			{
			if (waveOut != null && fileWaveStream != null)
				{
				TimeSpan currentTime = ( waveOut.PlaybackState == PlaybackState.Stopped ) ? TimeSpan.Zero : fileWaveStream.CurrentTime;
				if (fileWaveStream.Position >= fileWaveStream.Length)
					{
					sliderSeconds.Value = 0;
					labelSeconds.Content = "";
					//buttonStop.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
					buttonNext.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
					}
				else
					{
					sliderSeconds.Value = (int)currentTime.TotalSeconds;
					labelSeconds.Content = String.Format("{0:00}:{1:00}/{2:00}:{3:00}", (int)currentTime.TotalMinutes,
						currentTime.Seconds, (int)fileWaveStream.TotalTime.TotalMinutes, fileWaveStream.TotalTime.Seconds);
					}
				}
			else
				{
				sliderSeconds.Value = 0;
				}
			}


Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>