我正在使用背景音频播放器播放音频文件。我尝试使用 background.instance.track.duration.totalseconds 方法获取音频的持续时间。但是当我运行 app 方法时,每次都返回“0”。如果我通过断点运行代码,则会检索持续时间。下面是我的代码。
if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing)
{
progressBar1.Visibility = System.Windows.Visibility.Visible;
TotalTimeDisplay.Visibility = System.Windows.Visibility.Visible;
//this.TotalTimeDisplay.Time = TimeSpan.Parse("00:00:00.0");
imgplay.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("Images/player_pause_new.png", UriKind.Relative));
AudioTrack audioTrack = new AudioTrack(new Uri("a" + imgname + ".MP3", UriKind.Relative), "", "", "", null);
BackgroundAudioPlayer.Instance.Track = audioTrack;
duration = BackgroundAudioPlayer.Instance.Track.Duration.TotalMilliseconds;
}
请提出解决方案。在此先感谢。