c# - sound not playing at the right moment -


i created mediaelement background music in windows phone app , plays problem when tried add sound button when pressed

when debug , background music plays , when press button navigates me next page without playing sound created, , when press backbutton navigated page, plays it, why?

code:

private void play_click(object sender, routedeventargs e) {     mediaelement click = new mediaelement();     click.source = new uri ("/assets/sounds/press.mp3",urikind.relative);     click.position = timespan.zero;     click.volume = 1;     layoutroot.children.add(click);     click.play();     navigationservice.navigate(new uri("/navpage.xaml", urikind.relative)); } 

private void play_click(object sender, routedeventargs e)         {             mediaelement click = new mediaelement();             click.source = new uri ("/assets/sounds/press.mp3",urikind.relative);             click.position = timespan.zero;             click.volume = 1;             layoutroot.children.add(click);             click.play();          } 

you should handle outside button click,

navigationservice.navigate(new uri("/navpage.xaml", urikind.relative)); 

add event handler click , call separately,

 click.mediaended += click_completed;   void click_completed(object sender, routedeventargs e)         {            navigationservice.navigate(new uri("/navpage.xaml", urikind.relative));         } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -