Click here to Skip to main content
15,888,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
successfully stream file from URL but now i want calculate total time of file just like in media player . and when the audio play current time increase.
i done this by using wave file reader but i cant do this using media foundation reader

What I have tried:

<pre lang="c#">
using(var mf = new MediaFoundationReader("http://192.168.0.105/record//20180301/0005/03017988.wav"))
{
using(var wo = new WaveOutEvent())
{
    wo.Init(mf);
    wo.Play();
}
}
 WaveStream inputStream = new WaveFileReader(mf);
 private void timer1_Tick_1(object sender, EventArgs e)
        {
            try
            {
                TimeSpan currentTime = (wo.PlaybackState == PlaybackState.Stopped) ? TimeSpan.Zero : inputStream.CurrentTime;
                //trackBar.Value = Math.Min(trackBar.Maximum, (int)(100 * currentTime.TotalSeconds / inputStream.TotalTime.TotalSeconds));
                label1.Text = String.Format("{0:00}:{1:00}", (int)currentTime.TotalMinutes, currentTime.Seconds);
                trackBar.Minimum = 0;

            trackBar.Maximum = (int)(inputStream.TotalTime.TotalSeconds);
            if (trackBar.Value <= trackBar.Maximum)
                trackBar.Value = (int)(inputStream.CurrentTime.TotalSeconds);
        }
        catch
        {
            timer1.Stop();
        }}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900