问题描述
我有一个winforms表单,其中使用了MediaElement.一切都(或多或少)完美地工作.唯一的事情是,加载媒体文件(mp3)后,访问 NaturalDuration.TimeSpan.TotalSeconds
会引发异常
I have a winforms form in which I use a MediaElement. Everything is working (more or less) perfectly. The only thing is, after loading a media file (mp3) accessing NaturalDuration.TimeSpan.TotalSeconds
throws an exception
(由我自己翻译成德语)
(Translated from german by myself)
如何访问时间跨度属性?我发现的所有示例中都没有使用特殊设置(好吧,它们似乎是WPF原生的...)
How can I access the timespan property? There is no special setting used in all the examples I have found (ok, they seem to be WPF native...)
我正在Windows 7上使用VisualStudio Express .Net 4,C#.
I am using VisualStudio Express .Net 4, C# on Windows 7.
有任何提示吗?
推荐答案
您需要等待 MediaOpened
事件触发,之后 NaturalDuration
将可用.要检查值是否可用,可以使用 NaturalDuration.HasTimeSpan
属性.
You need to wait for MediaOpened
event to fire, NaturalDuration
will be available after that. To check if value is available, you can use NaturalDuration.HasTimeSpan
property.
这篇关于查询TimeSpan.TotalSeconds时,MediaElement.NaturalDuration引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!