Search code examples
c#wpftimespan

How to display the maximum duration of a song using timespan?


In my music player, there are 2 labels.

Label 1 is for showing the progress time:

lblTime.Content = TimeSpan.FromSeconds(sliProgress.Value).ToString(@"mm\:ss");

And label 2 is for showing the maximum duration of a song:

lblTime2.Content = TimeSpan.MaxValue.ToString(@"mm\:ss");

Label 1 was working well from start playing and when I move the slider. But the label 2 somehow doesn't show anything. I have tried using Properties.Duration syntax in taglib-sharp. But for me, it show too much details, since I just want show the minutes and the seconds, not the hours even the miliseconds.

What should I do to fix the label 2?


Solution

  • I suddenly found an idea about using ToString syntax to taglib, similar to as I did for label 1. Now it works as I expected, displaying just only minutes and seconds.

    This is the code I use:

    lblTime2.Content=tagFile.Properties.Duration.ToString(@"mm\:ss");