Ho to use MediaElement with relative URL in Windows Phone 7.1?

被刻印的时光 ゝ 提交于 2019-12-12 05:49:29

问题


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...


回答1:


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

<MediaElement x:Name="MyMedia"/>

Or in code

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

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



来源:https://stackoverflow.com/questions/15326878/ho-to-use-mediaelement-with-relative-url-in-windows-phone-7-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!