c# - WPF Storyboard延迟播放wma文件

标签 c# .net wpf audio storyboard

我是WPF的一个完整的初学者,并且有一个使用StoryBoard播放声音的应用程序。

public void PlaySound()
{
 MediaElement m = (MediaElement)audio.FindName("MySound.wma");
 m.IsMuted = false;
 FrameworkElement audioKey = (FrameworkElement)keys.FindName("MySound");
 Storyboard s = (Storyboard)audioKey.FindResource("MySound.wma");
 s.Begin(audioKey);
}

<Storyboard x:Key="MySound.wma">
 <MediaTimeline d:DesignTimeNaturalDuration="1.615" BeginTime="00:00:00" Storyboard.TargetName="MySound.wma" Source="Audio\MySound.wma"/>
</Storyboard>

我有一个可怕的滞后,有时要花10秒才能播放声音。
我怀疑这与以下事实有关:无论我等待多长时间-声音直到我离开该功能后才播放。我不明白我叫Begin,什么也没发生。有没有一种方法可以用立即播放且没有延迟的东西替换此方法或StoryBoard对象?

最佳答案

我将代码更改为-

<Button Cursor="Hand" HorizontalAlignment="Left" Margin="70,0,0,0" x:Name="MyButton"  Width="286" Content="Hi!" Focusable="False" IsTabStop="False">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.PreviewMouseLeftButtonDown">
                <EventTrigger.Actions>
                    <BeginStoryboard>
                        <Storyboard SlipBehavior="Slip" BeginTime="00:00:00">
                            <MediaTimeline Storyboard.TargetName="MySound_wma" Source="MySound.wma"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger.Actions>
            </EventTrigger>
    </Button.Triggers>
</Button>

现在看来一切正常,谢谢xD

关于c# - WPF Storyboard延迟播放wma文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3071155/

相关文章:

c# - 添加自定义列 resx 文件

c# - 为任意图像实现可点击的 map

c# - 更改样式中的 setter 值

c# - 旋转 Windows 屏幕键盘

c# - 我可以从 Winforms 应用程序同时将文件和模型上传到 MVC 4 操作吗?

c# - 使用从 EF 实体派生的 DTO 实体执行插入

c# - 如何在 "in"子句中使用 Entity Framework 中的参数?

c# - 如何比较 "look alike"的 Unicode 字符?

.net - 如何在 app.config 中使用双引号

c# - 如何获取方法的 MethodBase 对象?