I am using MediaTimeline and MediaClock to control the WMV video playback.
Timeline = new MediaTimeline(new Uri(VideoFileName));
Clock = Timeline.CreateClock(true) as MediaClock;
When I look at the Clock.NaturalDuration, value is set to Automatic and does not
contain duration TimeSpan yet.
When I assign Clock to MediaElement and video starts playing, I can now see the NaturalDuration.TimeSpan is present and OK.
Is there a way to get the video duration other than assigning clock to media element and playing?
Is there a way to get duration even without usage of media element (this would be the best)?
I had similar need to check out video length, so I read that this property is available when MediaOpened event is being raised, otherwise is set to Automatic - read this http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.naturalduration(v=vs.95).aspx
media.MediaOpened += new System.Windows.RoutedEventHandler(media_MediaOpened);
media.LoadedBehavior = MediaState.Manual;
media.UnloadedBehavior = MediaState.Manual;
media.Play();
void media_MediaOpened( object sender, System.Windows.RoutedEventArgs e )
{
progress.Maximum = (int)media.NaturalDuration.TimeSpan.TotalSeconds;
timer.Start();
isPlaying = true;
}
getting duration of video file in Win Rt App or Metro C#
string path = ApplicationData.Current.LocalFolder.Path;
StorageFile videoFile =
await StorageFile.GetFileFromPathAsync(presentationItem.Slide_path_local);
Windows.Storage.FileProperties.VideoProperties x =
await videoFile.Properties.GetVideoPropertiesAsync();
Duration videoDuration = x.Duration;
Best way to get duration of video file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With