public static Duration GetDuration(string fileName) { Duration naturalDuration = Duration.Automatic; Window w = new Window { Content = _videoElement = new MediaElement() { IsMuted = true }, IsHitTestVisible = false, Width = 0, Height = 0, WindowStyle = WindowStyle.None, ShowInTaskbar = false, ShowActivated = false }; _videoElement.MediaOpened += (sender, args) => { naturalDuration = _videoElement.NaturalDuration; _videoElement.Close(); w.Close(); }; _videoElement.LoadedBehavior = MediaState.Manual; _videoElement.UnloadedBehavior = MediaState.Manual; _videoElement.Source = new Uri(fileName); _videoElement.Play(); w.ShowDialog(); return naturalDuration; }
private void SetVideo(MediaElement player, AudioVisual audioVisual) { player.Close(); if (audioVisual.Video != null) { player.Source = audioVisual.Video; player.Play(); } }