Windows Phone 7.1 - Media Element not playing

牧云@^-^@ 提交于 2019-12-13 04:45:31

问题


Windows Phone 7.1/7.5/Mango app.

I have four different MediaElements on the page.

  • One is played upon Load of the page.

  • Rest 3 I Play() it upon leftMouseButtonClick on different image element on the page. I call Stop() in the MediaEnded event handler.

Issue: The last mediaElement in the top-down order won't play. So it's not the element itself bu the order of the element that is behaving weird.

I have read this where it talks about a single MediaElement which I don't understand.

Does anyone has any ideas on this?

Note: I don't have to play all sound at the same time. Only one sound at a time.

I found one reference that talks having single MediaElement only and dynamically set the Source in the code. I haven't tried it yet, will do soon.


回答1:


To confirm your last sentence, you can only have one MediaElement per page. You'll have to consider changing the source from the code-behind (or using data-binding) instead of having a MediaElement for each piece of audio. Having multiple MediaElements won't throw an error, but it will just override the behaviour of the previously added one (like you're experiencing).

To set the audio from the code-behind, you can use either the SetSource (which accepts a stream) method, or the Source property which reads a Uri.




回答2:


In my case, I get the error at the 6th media element. I try to put 14 Media Elements in a project (just to see what happens). You could also use SoundEffect from XNA if you really need to have a lot of sources playing at the same time or something



来源:https://stackoverflow.com/questions/8765671/windows-phone-7-1-media-element-not-playing

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