媒体元素不能在Windows Phone 7中播放音频?

时间:2010-07-20 09:45:13

标签: windows-phone-7

  

可能重复:
  adding media element in windows phone 7?

媒体元素即使正确显示属性也无法播放音频。

1 个答案:

答案 0 :(得分:1)

确实有效。

在代码中:

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

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

N.B。 “beep.wav”必须配置为“内容”。

在app构造函数中添加:

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(); }
}
相关问题