c# - Getting duration from BackgroundAudioPlayer -
i using background audio player play audio file.i have tried duration of audio using background.instance.track.duration.totalseconds method.but when run app method returned "0" everytime.the duration retrieved if run code through breakpoints. below code.
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; }
please suggest solution .thanks in advance.
try
backgroundaudioplayer.instance.playstatechanged += new eventhandler(instance_playstatechanged);
then
void instance_playstatechanged(object sender, eventargs e) { int duration = (sender backgroundaudioplayer).track.duration.totalmilliseconds; }
i not know why...but should start
Comments
Post a Comment