问题
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