Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

c# - MediaElement not playing audio from stream WP7

 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...