Silverlight:MediaElement 可以从下载流中播放吗?
我想知道是否可以从仍在下载的流中播放 MediaElement 中的视频,而不是等待它完成?我已经非常彻底地研究了这个主题,但没有找到明确的答案。
我正在尝试实现按需播放。我目前正在通过将 uri 分配给 MediaElement 的源来播放视频,这很有效。我想通过打开流中的 uri,并使用 SetSource 将流分配给 MediaElement 来更改此播放。
我编写了获取 uri、创建 WebClient 并使用 OpenReadAsync 开始读取的代码。我已将 AllowReadStreamBuffering 设置为 false,以便我可以在可用时立即从 OpenReadComplete 获取流(而不是等待它完成下载)。一旦获得 Stream 的句柄,我就将其分配给 MediaElement 并尝试播放。
目前这会导致 System.Exception: 2210 错误。据我所知,该资源存在并且可读,我不知道是否是我的代码错误,或者 MediaElement 是否根本不可能从不完整的流中进行播放。
如果使用 SetSource 和 Stream 无法实现这一点,是否可以使用 SetSource 和 MediaStreamSource 类?我确实查看了 MediaStreamSource 来完成此任务,但它似乎要求我编写代码来解析传入流并从中一次提取一帧,这听起来很痛苦。
I am trying to find out whether it is possible to play a video in a MediaElement from a stream which is still downloading, rather than waiting for it to finish? I have researched the topic pretty thoroughly, but found no definitive answer.
I am trying to implement playback on demand. I am currently playing the video by assigning the uri to the MediaElement's Source, and this works. I want to change this to play back by opening the uri in a Stream, and assigning the Stream to the MediaElement using SetSource.
I have written code which takes the uri, creates a WebClient, and uses OpenReadAsync to begin reading from it. I've set AllowReadStreamBuffering to false to allow me to get the stream from OpenReadComplete as soon as it's available (rather than waiting for it to finish downloading). As soon as I have a handle to the Stream, I assign it to the MediaElement and attempt playback.
This is currently resulting in a System.Exception: 2210 error. As I know the resource exists and is readable, I don't know whether it's my code that's wrong, or whether it's simply not possible for a MediaElement to play back from a stream that is incomplete.
If this is not possible using SetSource and a Stream, is it possible using SetSource and a MediaStreamSource class? I did look at MediaStreamSource for this task, but it seemed to require me to write code which parsed the incoming stream and extract a frame at a time from it, which sounded painful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论