public TimeSpan DurationOfMediaFile(string FilePath) { Version v = Environment.OSVersion.Version; // WIN7 APIs if (Environment.OSVersion.Version >= new Version(6, 1)) { using (ShellFile sf = ShellFile.FromFilePath(FilePath)) { ShellProperties props = sf.Properties; ShellProperties.PropertySystem psys = props.System; ulong?duration = psys.Media.Duration.Value; if (duration.HasValue) { return(TimeSpan.FromTicks((long)duration.Value)); } } } else { // LEGACY *** (XP and Vista) LegacyMediaDuration lmd = new LegacyMediaDuration(); return(lmd.GetMediaDuration(FilePath)); } return(TimeSpan.FromSeconds(0)); }
private void PopulateShellFileInfo(string fullPath) { try { if (!ShellFile.IsPlatformSupported) { return; } using (var timer = new TimingMetrics(TimingMetric.GettingShellInfo)) { using (ShellFile file = ShellFile.FromFilePath(fullPath)) { using (ShellProperties fileProperties = file.Properties) { ShellProperties.PropertySystem shellProperty = fileProperties.System; Project = shellProperty.Project.Value ?? ""; ProviderItemID = shellProperty.ProviderItemID.Value ?? ""; OriginalFileName = shellProperty.OriginalFileName.Value ?? ""; FileOwner = shellProperty.FileOwner.Value ?? ""; FileVersion = shellProperty.FileVersion.Value ?? ""; FileDescription = shellProperty.FileDescription.Value ?? ""; Trademarks = shellProperty.Trademarks.Value ?? ""; Link = shellProperty.Link.TargetUrl.Value ?? ""; Copyright = shellProperty.Copyright.Value ?? ""; Company = shellProperty.Company.Value ?? ""; ApplicationName = shellProperty.ApplicationName.Value ?? ""; Comment = shellProperty.Comment.Value ?? ""; Title = shellProperty.Title.Value ?? ""; CancellationHelper.ThrowIfCancelled(); MimeType = shellProperty.ContentType.Value ?? ""; InternalName = shellProperty.InternalName.Value ?? ""; ProductName = shellProperty.Software.ProductName.Value ?? ""; Language = shellProperty.Language.Value ?? ""; ComputerName = shellProperty.ComputerName.Value ?? ""; } } } } catch { } }