媒体元素无法在 Windows Phone 7 中播放音频? [英] media element doesn't play audio in windows phone 7?

查看:30
本文介绍了媒体元素无法在 Windows Phone 7 中播放音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
在 windows phone 7 中添加媒体元素?

即使正确提供属性,media 元素也无法播放音频.

media element doesn't play audio even correctly giving the properties.

推荐答案

确实有效.

在代码中:

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

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

注意beep.wav"必须配置为内容".

N.B. "beep.wav" must be configured as "Content".

在应用构造函数中添加:

In app constructor add:

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(); }
}

这篇关于媒体元素无法在 Windows Phone 7 中播放音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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