我试图做一些我认为很简单的事情,但事实并非如此。我想播放从API获得的URI中的声音剪辑。URI为音频剪辑提供绝对URI。
我试过使用MediaElement组件,但它在下载/播放剪辑时挂起UI。这意味着用户体验很差,而且可能也无法通过商店认证。
我也尝试过XNA框架中的SoundEffect类,但这会抱怨绝对URI --这似乎只适用于相对链接,因此是不够的。
我想知道在windows phone 8应用程序中播放不挂UI的声音剪辑还有什么其他选择
欢迎任何建议。
谢谢
发布于 2014-03-02 22:13:29
在网络或互联网上使用媒体文件会增加应用程序的延迟时间。在手机加载文件之前,你不能开始播放媒体。使用MediaElement.MediaOpened确定媒体何时准备就绪,然后调用.Play();
当然,您需要让用户知道媒体正在下载。我的示例使用SystemTray ProgressIndicator向用户显示消息。
XAML
<Grid x:Name="ContentPanel"
Grid.Row="1"
Margin="12,0,12,0">
<StackPanel>
<Button x:Name='PlayButton'
Click='PlayButton_Click'
Content='Play Media' />
<MediaElement x:Name='media1'
MediaOpened='Media1_MediaOpened'
AutoPlay='False' />
</StackPanel>
</Grid>码
private void Media1_MediaOpened(object sender, RoutedEventArgs e) {
// MediaOpened event occurs when the media stream has been
// validated and opened, and the file headers have been read.
ShowProgressIndicator(false);
media1.Play();
}
private void PlayButton_Click(object sender, RoutedEventArgs e) {
// the SystemTray has a ProgressIndicator
// that you can use to display progress during async operations.
SystemTray.ProgressIndicator = new ProgressIndicator();
SystemTray.ProgressIndicator.Text = "Acquiring media - OverTheTop.mp3 ";
ShowProgressIndicator(true);
// Get the media
media1.Source =
new Uri(@"http://freesologuitar.com/mps/DonAlder_OverTheTop.mp3",
UriKind.Absolute);
}
private static void ShowProgressIndicator(bool isVisible) {
SystemTray.ProgressIndicator.IsIndeterminate = isVisible;
SystemTray.ProgressIndicator.IsVisible = isVisible;
}https://stackoverflow.com/questions/22117854
复制相似问题