c# - Media Element will not play a song for the first time, or at all. -
i have little problem playing song selected simple listpickerflyout, now, works
private async void musicfileslist_itemspicked(listpickerflyout sender, itemspickedeventargs args) { storagefile selectedmusic = sender.selecteditem storagefile; using (irandomaccessstream stream = await selectedmusic.openasync(fileaccessmode.read)) { this.musicplayer.setsource(stream, selectedmusic.contenttype); this.musicplayer.play(); } }
it works fine except tiny little bug disturbs me- first time select song- not play, second time. debugged , saw enters handler first time too, reason plays second time. strange, told should write event handler following way -
private void musicfileslist_itemspicked(listpickerflyout sender, itemspickedeventargs args) { storagefile selectedmusic = sender.selecteditem storagefile; this.musicplayer.autoplay = true; this.musicplayer.source = new uri(selectedmusic.path); this.musicplayer.play(); }
to me - looks fine, won't play song @ all. explain why first 1 not working properly, second 1 not working @ , proper way play music using media element ?
Comments
Post a Comment