问题
string url = re["response"][0]["url"].ToString();
MediaElement mm = new MediaElement();
mm.Source = new Uri(url,UriKind.RelativeOrAbsolute);
mm.AutoPlay = true;
mm.Volume = 0.7;
mm.Play();
But no changes, the adudio not starts.How I can resolve this?
回答1:
You need to add your MediaElement to your VisualTree before playing it, since you're creating it in the codebehind. For example, assuming you have LayoutRoot
and that your url
is correct, this should work.
string url = re["response"][0]["url"].ToString();
MediaElement mm = new MediaElement();
mm.Source = new Uri(url,UriKind.RelativeOrAbsolute);
mm.AutoPlay = true;
mm.Volume = 0.7;
LayoutRoot.Children.Add(mm);
mm.Play();
来源:https://stackoverflow.com/questions/7018335/mediaelement-not-playing-audio-from-stream-wp7