为什么不会在Windows Phone 7的这个音频播放? [英] Why won't this Audio play in Windows Phone 7?

查看:145
本文介绍了为什么不会在Windows Phone 7的这个音频播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Silverlight为Windows Phone 7应用程序来播放音频。我有一个设置为资源的生成操作的MP3音频文件。要播放的声音,我使用的:

I am trying to play audio in my Silverlight for Windows Phone 7 app. I have an MP3 audio file with its build action set to resource. To play the sound, I use:

SoundEffectInstance sfi = null;
...
        Stream source = Application.GetResourceStream(new Uri("/Bird Calls;component/Crow.mp3", UriKind.Relative)).Stream;
        Microsoft.Xna.Framework.Audio.SoundEffect effect = SoundEffect.FromStream(source);
        sfi = effect.CreateInstance();
        sfi.Play();

这code抛出在SoundEffect.FromStream方法InvalidOperationException异常。

This code throws a InvalidOperationException at the SoundEffect.FromStream method.

推荐答案

SoundEffect中不能播放MP3文件。如果你想播放MP3文件,你应该使用的MediaPlayer像

SoundEffect can't play mp3 file. If you want to play mp3 file, you should use MediaPlayer like that

private Song song;


string musicUrl = string.Format("/Bird Calls;component/Crow.mp3");
song = Song.FromUri("name", new Uri(musicUrl, UriKind.Relative));
FrameworkDispatcher.Update();
MediaPlayer.IsRepeating = true;
MediaPlayer.Play(song);

这篇关于为什么不会在Windows Phone 7的这个音频播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆