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
Post a Comment