如何在Windows Phone 7.1中将MediaElement与相对URL结合使用? [英] Ho to use MediaElement with relative URL in Windows Phone 7.1?

查看:112
本文介绍了如何在Windows Phone 7.1中将MediaElement与相对URL结合使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已证明一切,但此代码无法在Windows Phone 7.1中运行 私人MediaElement媒体;

I proved everything but this code does not run in Windows Phone 7.1 private MediaElement media;

private MediaElement media;
    // Costruttore
    public MainPage()
    {
        this.InitializeComponent();

        media = new MediaElement();
        media.Source = new Uri("Risorse/Brani/00 Mai 1771.mp3", UriKind.Relative);
        media.Play();

    }

我提到的文件存在并且没有引发错误...

The file I mentioned exists and no error is thrown...

推荐答案

MediaElement控件必须放入可视树中.您可以通过将元素放置在xaml中来实现

The MediaElement control must be put into the visual tree. You can accomplish this by placing the element in xaml

<MediaElement x:Name="MyMedia"/>

或在代码中

media = new MediaElement();
LayoutRoot.Children.Add(media)

一旦它出现在视觉树中,您就可以玩了.

Once it is in the visual tree, you will be able to play.

这篇关于如何在Windows Phone 7.1中将MediaElement与相对URL结合使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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