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

New Post: Play position

$
0
0

OK, I have done this, but this method is rather slow. While playing, I can hear something like ticks. This is my code.

(These ticks are only when I draw the line. The line is drawn on WaveViewer. In other words WaveViewer is parent of the line).

//indicatorTimer is a dispatcherTimer with interval set to 100
//indicator is Microsoft.VisualBasic.PowerPacks.LineShape

private void indicatorTimer_Tick(object sender, EventArgs args)
{
    if (indicator.Visible)
    {
        int ms = (waveStream.CurrentTime.Minutes * 60 * 1000) + (waveStream.CurrentTime.Seconds * 1000) + waveStream.CurrentTime.Milliseconds;
        int x = (ms * (waveStream.WaveFormat.SampleRate / 1000)) / samplesPerPixel;
        DrawIndicator(x);
        lastX = x;
    }

    if (OnPlayProgress != null) OnPlayProgress(this, waveStream.CurrentTime);
    if (waveStream.TotalTime == waveStream.CurrentTime) indicatorTimer.Stop();
}

private void DrawIndicator(int x)
{
    indicator.X1 = x;
    indicator.X2 = x;
}

//in OnPlayProgressEvent I have only one line of code:
timeLabel.Text = String.Format("{0:00}:{1:00}", currentTime.Minutes, currentTime.Seconds);



Viewing all articles
Browse latest Browse all 5831

Trending Articles



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