WPF MediaElement 自然持续时间

发布于 2024-09-05 23:00:09 字数 346 浏览 1 评论 0原文

我有一个 MediaElement,我将其 Source 设置为基于有效字符串的新 Uri。

例如:

MediaElementName.Source = new Uri("string");

该字符串是一个有效的路径,调试后,有时它会设置“MediaElementName”的 NaturalDuration,有时则不会。

我已经在谷歌上搜索了至少 2 个小时,但没有任何工作结果。

这里有人有吗为什么有时会设置 NaturalDuration,有时不会?我能够播放 wav,但它不知道 wav 文件有多长(持续时间)。

任何帮助或想法表示赞赏,谢谢!

-BTG

I have a MediaElement which I set its Source to a new Uri based on a valid String.

For example:

MediaElementName.Source = new Uri("string");

The string is a valid path, and after debugging, sometimes it sets the "MediaElementName"'s NaturalDuration, sometimes it does not..

I have been googling for at least 2 hours now with no working results..

Does anyone on here have an idea of why sometimes it would set the NaturalDuration, and sometimes it would not? I AM able to play the wav, but it has no idea on how long the wav file is (time duration).

Any help or thoughts are appreciated, thanks!!

-BTG

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

迷爱 2024-09-12 23:00:09

我知道这太晚了,但无论如何,我的经验是这个问题的两个变体:

a)编解码器(flac 可以是一个例子)无法找出持续时间。检查并查看 Windows Media Player 是否显示进度条(我拥有的一些由自定义硬件生成的 flac 文件存在此问题)我怀疑文件中没有“索引”。另外,flac 格式会给出不同的结果,具体取决于它是在本地文件上运行还是通过 http 运行(我怀疑这是因为当它无法在流中查找时,它无法找到长度)。

b)一些编解码器在渲染一些材料之前不会给出持续时间,为了解决这个问题,我运行了一个计时器,它使用 Player.NaturalDuration.HasTimeSpan ,然后获取 TimeSpan 。这通常会在媒体开始播放后的几秒钟内持续。检查 Player_MediaOpened 中的时间跨度无法可靠地工作。

I know this is way tooooo late but anyway my experience has been two variants of this problem

a) The codec (flac can be an example of this) can't find out the duration. Check and see if windows media player displays a progress bar (some flac files I had that were being generated by custom hardware had this problem) I suspect there was no "index" within the file. Also the flac format gives different results depending if it's running on a local file or over http (I suspect this is because when it can't seek within a stream it can't find the length).

b) Some codecs don't give a duration until they have rendered some material, to solve this I have a timer running which uses Player.NaturalDuration.HasTimeSpan and then gets the TimeSpan. This usually gets a duration within a couple seconds of the media starting to play. Checking the timespan in Player_MediaOpened doesn't reliably work.

嘿咻 2024-09-12 23:00:09

实际上我只是后退了一步,而是使用 FileInfo 检索了信息。

FileInfo test = new FileInfo("myFilepath");
double size = test.Length;

I actually just took a step back and instead retrieved the information using FileInfo.

FileInfo test = new FileInfo("myFilepath");
double size = test.Length;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文