Windows Phone 7.1 - Media Element not playing

2019-08-31 04:43发布

问题:

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