I'm trying to achieve this flow when a page is opened in WP7:
play storyboard "blink" ⇒ play sound ⇒ play storyboard "movement"
I added the sound as a MediaElement as you can see in the code. I had to set AutoPlay="False", or the sound would play instantly when page opens.
The开发者_JAVA百科 problem is, when the blink storyboard ends the sound is never played. I tacked the MediaEnded trigger onto the MediaElement in the belief that it would refer to the sound specified in the MediaElement. But it does nothing. I tried specifying the sound once more within the PlaySoundAction's "Source" property but it still does not play the sound. I'm thinking the "autoplay=false" thing of MediaElement is a culprit, but I can't take it off as described above.
<MediaElement x:Name="mysound" HorizontalAlignment="Left" Height="0" Source="/mysound.mp3" Stretch="Fill" VerticalAlignment="Top" Width="0" Volume="1" AutoPlay="False">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MediaEnded">
<eim:ControlStoryboardAction Storyboard="{StaticResource movement}"/>
</i:EventTrigger>
<eim:StoryboardCompletedTrigger Storyboard="{StaticResource blink}">
<eim:PlaySoundAction Volume="1"/>
</eim:StoryboardCompletedTrigger>
</i:Interaction.Triggers>
</MediaElement>
I have had a lot of issues with MediaElement as well, and hence prefer using the following to fix this issue.
http://www.dotnetscraps.com/dotnetscraps/post/Play-multiple-sound-files-in-Silverlight-for-Windows-Phone-7.aspx
See if it helps.
Your mediaEnded handler is never firing as the media is never being played.
Handle the Completed event on the "blink" storyboard. Have that play the sound. Then have the mediaEnded handler start the next stroryboard.
You may find this easier to wire up in C# rather than xaml. (You can always change it once you've got it working, if you wish.)
精彩评论