Windows phone 7 需要Windows Phone 7上的小帮助吗
我正在创建一个应用。。我面临一个小问题。我想得到这个东西。。。 我有一个单选按钮。现在,每当单击此单选按钮时,我想在循环中播放一段小音乐。我正在使用visual studio。。无法对其使用表达式。 我正在使用以下代码Windows phone 7 需要Windows Phone 7上的小帮助吗,windows-phone-7,Windows Phone 7,我正在创建一个应用。。我面临一个小问题。我想得到这个东西。。。 我有一个单选按钮。现在,每当单击此单选按钮时,我想在循环中播放一段小音乐。我正在使用visual studio。。无法对其使用表达式。 我正在使用以下代码 public partial class Page3 : PhoneApplicationPage { private SoundEffect s1; public Page3() { Init
public partial class Page3 : PhoneApplicationPage
{
private SoundEffect s1;
public Page3()
{
InitializeComponent();
GameTimer gameTimer = new GameTimer();
gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(10000);
// Call FrameworkDispatcher.Update to update the XNA Framework internals.
gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } };
// Start the GameTimer running.
gameTimer.Start();
// Prime the pump or we'll get an exception.
FrameworkDispatcher.Update();
LoadSound("Views/1.wav", out s1);
}
private void LoadSound(String SoundFilePath, out SoundEffect Sound)
{
// For error checking, assume we'll fail to load the file.
Sound = null;
try
{
// Holds informations about a file stream.
StreamResourceInfo SoundFileInfo = App.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative));
// Create the SoundEffect from the Stream
Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
}
catch (NullReferenceException)
{
// Display an error message
MessageBox.Show("Couldn't load sound " + SoundFilePath);
}
}
private void radioButton1_Checked(object sender, RoutedEventArgs e)
{
try
{
s1.Play();
}
catch (NullReferenceException)
{
MessageBox.Show("Can't play, s1 is null.");
}
}
这是我用来播放声音的代码,它可以工作:
private void PlaySound()
{
Stream stream = TitleContainer.OpenStream("Media/Sounds/SomeFile.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
}
另外,确保您的声音文件被标记为内容