积极答复者
WP8的一个Page里如何播放多个音效?

问题
-
我看之前有同学提过这个问题,但是我按照方法增加了,会报错。
在一个页面中播放多个音效可以添加对Microsoft.Xna.Framework的引用,使用其中的SoundEffect.Play 。
具体可以参考这个Blog:Play multiple sound files in Silverlight for Windows Phone 7
按照这个网页上的说法,我的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using MediaTest.Resources;using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
namespace MediaTest
{
public partial class MainPage : PhoneApplicationPage
{
// 构造函数
public MainPage()
{
InitializeComponent();
PlaySound("/Assets/GAME_WIN.wav");
}
public void PlaySound(string soundFile)
{
using (var stream = TitleContainer.OpenStream(soundFile))
{
var effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
//Thread.Sleep(effect.Duration);
}
}
}
}问题时在粗体字这行中的stream报null,直接异常,但是我的soundFile的字符串路径是正确的,属性也按照博客上设置为Content,出错的原因在哪里呢?
答案
-
你好,
对于循环播放,你可以参考msdn推荐的做法:
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 iwpfModerator 2013年3月25日 2:41
全部回复
-
你好,
对于循环播放,你可以参考msdn推荐的做法:
Mark Yu - MSFT
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 iwpfModerator 2013年3月25日 2:41