如何测试Silverlight是否可以播放流?

发布于 2024-10-06 15:27:24 字数 286 浏览 9 评论 0原文

我想写一个像下面这样的方法。但是,如果 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2024-10-13 15:27:24

我不确定您是否正在寻找测试失败或测试播放媒体类型的能力,因此...

您可以为 MediaFailed 添加事件处理程序,无论是在 XAML 中还是在这两种情况的代码后面。主动检查可玩性需要一些创造力,例如拥有一些非常小(<1秒)且无声的各种类型的“样本”媒体文件,其用于测试可玩性的目的并且对用户来说是透明的。

对于连线事件后面的 C# 代码,并添加新事件:

void yourPage_Loaded(object sender, RoutedEventArgs e)
{
  ME.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(ME_MediaFailed);
}

void ME_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
  add your code to handle the exception here.
}

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:

void yourPage_Loaded(object sender, RoutedEventArgs e)
{
  ME.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(ME_MediaFailed);
}

void ME_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
  add your code to handle the exception here.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文