Post by donqstuart on May 31, 2016 23:23:57 GMT 10
I'm setting up a media player following this excellent tutorial: www.youtube.com/watch?v=hMK4Z_WMnxAMostly things are going fine, and I've got a trackbar controlling the media playback position, which is set up from the movie's NaturalDuration when the movie loads. However I've found that there are some MP4 files where the NaturalDuration never actually sets a TimeSpan. In most cases, a proper TimeSpan is created (MediaElement1.NaturalDuration.TimeSpan) which I can then read the .TotalMilliseconds property from in order to set the trackbar. In certain movies- and I don't know why some would do this and others don't, as they're all from the same source- despite the fact the movie has already loaded and is playing, the NaturalDuration value still returns "Automatic". Without it, I can't set up the trackbar, as I have no other way of working out how long the movie is. Does anyone know why this might be happening, or alternatively, whether there's another way to find out how long the movie is? Thanks Stuart
|
|
Post by donqstuart on Jun 1, 2016 20:38:22 GMT 10
Although I'd still be interested in an answer to this question, I thought I'd best pop back in and mention that I have stopped using NaturalDuration for what I need. It's simply not accurate enough. I have movies that are 29 frames long at 24 frames per second, and the NaturalDuration.TotalMilliseconds value is being returned as '1000' which is simply wrong.
I've switched to using FFprobe to get the movie's accurate duration as it's loaded. It's less elegant, but it's accurate.
|
|
Post by Nathan Lecompte on Jun 2, 2016 16:54:27 GMT 10
Oh, I didn't get notified about this question for some reason...that's weird; must be a bug with the notifications :/ So, problem solved? I'm going to give you my answer anyways: I used MediaElement1.Position.Duration to get the total duration of the video being played in the MediaElement. Hope this helps!
|
|