WP7 - playing mediaelement after page is loaded

我与影子孤独终老i 提交于 2019-12-11 18:55:57

问题


I have this MediaElement in my xaml page:

<MediaElement 
            x:Name="soundMenu" 
            Source="Sounds/menu.wav" 
            AutoPlay="False" MediaEnded="soundMenu_MediaEnded"/>

and I want it to play when page is loaded (like background music):

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
     soundMenu.Play()
}

It doesn't work. When I click on some button and try to play music it's working but this isn't. What's wrong with this? How can I play sound after page is loaded?

P.s.: I know I must check if user is playing something. I just for now want to solve this issue:)


回答1:


It takes some time for the MediaElement to initialize. I guess in your case you try to start playing before the sound file has been loaded. Set AutoPlay to true or call the Play method in MediaOpened event handler.



来源:https://stackoverflow.com/questions/14335987/wp7-playing-mediaelement-after-page-is-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!