如何测试Silverlight是否可以播放流?
我想写一个像下面这样的方法。但是,如果 Silverlight 无法本机播放流,我希望它遍历 MediaStreamSource 类的列表,并依次尝试每个类,直到其中一个可以工作,或者不再可以尝试。我的问题是,如何判断下面的方法是否足以满足特定的流。
public static void OpenMedia(this MediaElement ME, Stream FileData)
{
ME.SetSource(FileData);
}
我需要一些代码来执行,以防无法播放媒体。
I want to write a method like the one bellow. However, in the event that Silverlight is unable to play the stream natively, I would like it to go through a list of MediaStreamSource classes, and try each one in turn till either one of them works, or it has no more to try. My question is, how do I tell whether the method below is sufficient for a particular stream.
public static void OpenMedia(this MediaElement ME, Stream FileData)
{
ME.SetSource(FileData);
}
I need some code to execute in the event that this fails to play the media.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是否正在寻找测试失败或测试播放媒体类型的能力,因此...
您可以为 MediaFailed 添加事件处理程序,无论是在 XAML 中还是在这两种情况的代码后面。主动检查可玩性需要一些创造力,例如拥有一些非常小(<1秒)且无声的各种类型的“样本”媒体文件,其用于测试可玩性的目的并且对用户来说是透明的。
对于连线事件后面的 C# 代码,并添加新事件:
I'm not sure if you are looking for testing failure or testing for the ability to play the media type so...
You can add an event handler for MediaFailed, either in the XAML or he code behind for both cases. Checking for playability proactively would take some creativity, such as having some "sample" media files of various types that are very small (< 1 second) and silent which serve the purpose of testing playability and it would be transparent to the user.
For C# code behind wire the event, and add the new event: