如何在不使用 XAML 的情况下在 Silverlight 中播放声音
看起来 MediaElement
需要 XAML 才能工作。
所以这个简单的代码不起作用:
MediaElement me = new MediaElement();
me.Volume = 1;
me.AutoPlay = false;
me.Source = new Uri("http://www.robtowns.com/music/blind_willie.mp3");
me.Play();
是否有另一种方法可以使用 MVVM 在 Silverlight 4 中播放声音 - 或者我是否必须在 XAML 中找到媒体元素的占位符?
该线程描述了如何在 Win Phone 7 中使用 XNA - 但我说的是常规 Silverlight http://social.msdn .microsoft.com/Forums/en-US/windowsphone7series/thread/60e7e4b4-31dc-4a81-bdfb-e2c80e761a1c
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
控件仍然需要在可视化树中才能操作。如果您不希望它实际出现,可以将其折叠。但你需要做类似的事情:
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: