2010-07-20 88 views

回答

1

它確實有效。

在代碼:

using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Audio; 

var stream = TitleContainer.OpenStream("beep.wav"); 
       var effect = SoundEffect.FromStream(stream); 
       effect.Play(); 

注: 「beep.wav」必須配置爲「內容」。

在應用程序的構造函數中添加:

this.ApplicationLifetimeObjects.Add(new XNAAsyncDispatcher(TimeSpan.FromMilliseconds(50))); 

也將添加以下類:

public class XNAAsyncDispatcher : IApplicationService 
{ 
    private DispatcherTimer frameworkDispatcherTimer; 

    public XNAAsyncDispatcher(TimeSpan dispatchInterval) 
    { 
     this.frameworkDispatcherTimer = new DispatcherTimer(); 
     this.frameworkDispatcherTimer.Tick += new EventHandler(frameworkDispatcherTimer_Tick); 
     this.frameworkDispatcherTimer.Interval = dispatchInterval; 
    } 

    void IApplicationService.StartService(ApplicationServiceContext context) { this.frameworkDispatcherTimer.Start(); } 
    void IApplicationService.StopService() { this.frameworkDispatcherTimer.Stop(); } 
    void frameworkDispatcherTimer_Tick(object sender, EventArgs e) { FrameworkDispatcher.Update(); } 
}