Wpf 自定义媒体元素
嘿伙计们,我对 wpf 还很陌生,所以我需要一些帮助,这就是我想要做的。
我想创建一个自定义媒体元素,我希望能够加载视频并播放 15 秒到 1 分钟的视频,我希望能够根据用户设置在加载时动态设置它。我基本上将大量视频加载到列表视图控件中,并且希望播放视频,但我试图通过仅播放视频的一小部分预览来节省资源。
我研究过
- 自定义控件的事情 - 有些丢失了
- 子类化
- 预构建控制
我只是真的不确定下一步该去哪里。我非常感谢您能给我的任何帮助。
Hey guys I'm fairly green when it comes to wpf, so I need a little help, here is what im looking to do.
I want to create a custom media element, I want to be able to load a video and play any where from 15 secs to 1 min of the video, I want to be able to dynamically set this on load up based on user settings. I'm loading tons of videos essentially into a list view control and I want the video to play, but im trying to save on resources by playing only a small preview of the video.
Things I've looked into
- custom control - somewhat lost
- subclassing
- pre build control
Im just really unsure on where to go next. I would greatly appericate any help you can give me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于您对要求的评论扩展,我建议您使用普通的 MediaElement,但为其分配视频的“预览”版本,该版本仅包含您想要显示的片段并降低了分辨率,以降低负载占用量。
因此,您的模型将具有两个属性,即 PreviewUri 和 SourceUri。在 PreviewUri 中,您存储视频的“预览”版本;在 SourceUri 中,您存储“完整”版本。在 ListBox 或 ItemsControl 中,您将使用绑定到 PreviewUri 的 MediaElements。当用户进行选择时,您将主 MediaElement 的 Source 设置为 SourceUri。所以你的列表框看起来像这样:
你的模型看起来像这样:
你的代码看起来像这样:
如何显示全尺寸视频将取决于你想要触发什么以及全尺寸视频在哪里视频显示。使用 ListBox 而不是循环并将子项添加到 StackPanel 可能会有所帮助,因为您可以使用 SelectedItemChanged 事件、数据绑定到 SelectedItem 或使用 IsSynchronizedWithCurrentItem 属性。
Given your comments expanding on the requirement, I'd suggest that you use the normal MediaElement, but assigning it a "preview" version of the video that only includes the fragment you want to show and has reduced resolution so as to keep load footprint down.
Thus, your model will have two properties, say PreviewUri and SourceUri. At the PreviewUri, you store the "preview" version of the video; at the SourceUri, you store the "full" version. In your ListBox or ItemsControl, you'll use MediaElements bound to the PreviewUri. When the user makes a selection, you'll set the Source of the main MediaElement to the SourceUri. So your ListBox will look something like this:
your model will look something like this:
and your code behind will look something like this:
How you show the full-size video will depend on what you want to trigger this and where the full-size video displays. Using a ListBox rather than looping and adding children to a StackPanel may help with this because you can use the SelectedItemChanged event, databind to SelectedItem or use the IsSynchronizedWithCurrentItem property.