在故事板上播放声音完成

发布于 2024-11-28 23:14:20 字数 1127 浏览 0 评论 0原文

我试图在 WP7 中打开页面时实现此流程:

播放故事板“闪烁”⇒ 播放声音 ⇒ 播放故事板“运动”

我将声音添加为 MediaElement,如您在代码中看到的那样。我必须设置 AutoPlay="False",否则页面打开时声音会立即播放。

问题是,当眨眼故事板结束时,声音永远不会播放。我将 MediaEnded 触发器附加到 MediaElement 上,因为我相信它将引用 MediaElement 中指定的声音。但它什么也没做。我尝试在 PlaySoundAction 的“Source”属性中再次指定声音,但它仍然不播放声音。我认为 MediaElement 的“autoplay=false”是罪魁祸首,但我无法按照上面的描述将其删除。

            <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'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 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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眸中客 2024-12-05 23:14:20

我在 MediaElement 方面也遇到了很多问题,因此更喜欢使用以下方法来解决此问题。

http:// /www.dotnetscraps.com/dotnetscraps/post/Play-multiple-sound-files-in-Silverlight-for-Windows-Phone-7.aspx

看看是否可以有帮助。

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.

静谧幽蓝 2024-12-05 23:14:20

您的 mediaEnded 处理程序永远不会触发,因为媒体永远不会被播放。

处理 已完成事件。让其播放声音。然后让 mediaEnded 处理程序启动下一个情节提要。

您可能会发现在 C# 中连接比在 xaml 中更容易。 (如果您愿意,一旦您愿意,您可以随时更改它。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文