gpt4 book ai didi

c# - 多个 MediaElement 停止工作 wp8

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:40 24 4
gpt4 key购买 nike

private void Image_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
snare.Play();

}

private void tom3Img_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
tom3.Play();
}

private void tom2Img_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
tom2.Play();
}

private void tom1Img_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
tom1.Play();
}

private void kik_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
kick.Play();
}

private void lCrash_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
crashl.Play();
}

private void RCrash_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
crashr.Play();
}

在 xml 中,每个声音都有单独的元素

<MediaElement Name="snare" HorizontalAlignment="Left" Height="19" 
Margin="385,566,0,0" VerticalAlignment="Top" Width="42"
Visibility="Collapsed" AutoPlay="False" Volume="150" Source="/Music/snare.wav"/>

这些是我的 xml 和 cs 代码,我正在尝试以与我为 Windows 应用商店应用程序相同的方式创建架子鼓。问题我有时无法理解某些事件是否有效,如果我对另一个事件进行任何更改则停止。

文件夹中的所有声音文件都称为 Music 我尝试在 cs 中创建一个媒体元素并通过 cs 代码设置源ex snare.Source = new Uri("/Music/snare", UriKind.Relative);它也不起作用。如果有人可以帮助我解决这个问题。音频文件真的很短

最佳答案

如果我已经正确理解了您的需求,那么您的问题是 Windows Phone MediaElement 一次只能播放一个轨道/文件(来源 msdn):

When a MediaElement control plays audio or video content, any background sounds or media already playing are halted. The app launches the playback experience when the user taps the control. Only one MediaElement control can operate at a time.

要做这样的事情,你可能必须使用 XNA .这是一个有趣的 link这可能对您和一些精选的报价有帮助:

作者使用 Windows Store App/WP8 的体验似乎与您的非常接近:

First, I’ve written Windows 8 ‘Metro’ style apps which have played sounds nicely, so when we started porting a Win8 app to WP8, AND understanding that now WP8 is supposed to use the same kernel as Win8, I thought porting the sounds would be a breeze. Turns out there are some subtle (and not-so-subtle) differences in the two platforms.

所以他也有同样的问题:

Another ‘gotcha’ So far, we have only seen MediaElements used to play sounds. However, on WP8, it turns out that one and ONLY one media element can be playing at a time. SO – what to do if you need to have multiple simultaneous sound effects playing together, as in a game? Well, that’s where we can taps the XNA library and it’s SoundEffect.

最后,他得出了这个结论:

Conclusion So in the end, I settled on using the media element for playing the background music in my app so I could start/stop long-playing sound files at will, and using the SoundEffect from XNA to play the sound effects, rapid-fire, with multiple sounds playing all at once. Seems to work for me, best of luck to you!

关于c# - 多个 MediaElement 停止工作 wp8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19600053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com