使用NaturalDuration获取音频的时长

#region customizeTime

                if (mediaElement.NaturalDuration.TimeSpan.Seconds < 10)

                    sec = "0" + mediaElement.Position.Seconds.ToString();

                else

                    sec = mediaElement.NaturalDuration.TimeSpan.Seconds.ToString();



                if (mediaElement.NaturalDuration.TimeSpan.Minutes < 10)

                    min = "0" + mediaElement.NaturalDuration.TimeSpan.Minutes.ToString();

                else

                    min = mediaElement.NaturalDuration.TimeSpan.Minutes.ToString();



                if (mediaElement.NaturalDuration.TimeSpan.Hours < 10)

                    hours = "0" + mediaElement.NaturalDuration.TimeSpan.Hours.ToString();

                else

                    hours = mediaElement.NaturalDuration.TimeSpan.Hours.ToString();



                if (mediaElement.NaturalDuration.TimeSpan.Hours == 0)

                {



                    endTimeTextBlock.Text = min + ":" + sec;

                }

                else

                {

                    endTimeTextBlock.Text = hours + ":" + min + ":" + sec;

                }



                #endregion customizeTime

 

你可能感兴趣的:(NAT)