Looks like MediaElement
requires XAML to work.
So this simple code doesn't work开发者_运维百科 :
MediaElement me = new MediaElement();
me.Volume = 1;
me.AutoPlay = false;
me.Source = new Uri("http://www.robtowns.com/music/blind_willie.mp3");
me.Play();
Is there another way to play sound in Silverlight 4 with MVVM - or do I have to find a placeholder for the media element in my XAML ?
This thread describes how to use XNA for Win Phone 7 - but I'm talking regular Silverlight http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/60e7e4b4-31dc-4a81-bdfb-e2c80e761a1c
The control still needs to be in the visual tree to operate. If you don't want it to actually appear, you could have it collapsed. But you'll need to do something like:
me.Visibility = Visibility.Collapsed;
LayoutRoot.Children.Add(me);
精彩评论