Yizzho/peek/videos (#25983)

* Add basics of VideoPreviewer to build on

* WIP

* Minimal working code, todo next:dimension + MTC

* Nits

* Change back to GetImageSize as it indeed doesn't work with videos

* Add win32 helper methods to get video size; Refactor get size operation;

* Remove unused code

* Set VideoTask; Add message error for HR result;

* Add open read only for filestream

* Remove unused code

* Update expect.txt

* Remove comment

* Cleanup code

* Force pause videopreview on previewer change

---------

Co-authored-by: Jojo Zhou <yizzho@microsoft.com>
Co-authored-by: Yawen Hou <yawenhou@microsoft.com>
Co-authored-by: Clint Rutkas <clint@rutkas.com>
Co-authored-by: Yawen Hou <Sytta@users.noreply.github.com>
Co-authored-by: Samuel Chapleau 🌈 <sachaple@microsoft.com>
This commit is contained in:
Jojo Zhou
2023-05-15 14:06:08 -07:00
committed by GitHub
parent 5aa58bf922
commit a0b9af039d
15 changed files with 222 additions and 32 deletions

View File

@@ -33,5 +33,29 @@ namespace Peek.Common.Extensions
return tcs.Task;
}
/// <summary>
/// Run work on UI thread safely.
/// </summary>
/// <returns>True if the work was run successfully, False otherwise.</returns>
public static Task RunOnUiThread(this DispatcherQueue dispatcher, Action work)
{
var tcs = new TaskCompletionSource();
dispatcher.TryEnqueue(() =>
{
try
{
work();
tcs.SetResult();
}
catch (Exception e)
{
tcs.SetException(e);
}
});
return tcs.Task;
}
}
}

View File

@@ -8,6 +8,7 @@ using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using Peek.Common.Helpers;
using Peek.Common.Models;
using Scripting;
using Windows.Foundation;
@@ -19,17 +20,12 @@ namespace Peek.Common.Extensions
{
public static Size? GetImageSize(this IFileSystemItem item)
{
Size? size = null;
return PropertyStoreHelper.TryGetUintSizeProperty(item.Path, PropertyKey.ImageHorizontalSize, PropertyKey.ImageVerticalSize);
}
var width = item.Width;
var height = item.Height;
if (width != null && height != null)
{
size = new Size((int)width, (int)height);
}
return size;
public static Size? GetVideoSize(this IFileSystemItem item)
{
return PropertyStoreHelper.TryGetUintSizeProperty(item.Path, PropertyKey.FrameWidth, PropertyKey.FrameHeight);
}
public static Size? GetSvgSize(this IFileSystemItem item)

View File

@@ -7,24 +7,13 @@ using System.Globalization;
using System.Runtime.InteropServices;
using Peek.Common.Extensions;
using Peek.Common.Models;
using Windows.Foundation;
using Windows.Win32.UI.Shell.PropertiesSystem;
namespace Peek.Common.Helpers
{
public static partial class PropertyStoreHelper
{
/// <summary>
/// Gets a uint type value from PropertyStore from the given item.
/// </summary>
/// <param name="path">The file/folder path</param>
/// <param name="key">The property key</param>
/// <returns>a nullable uint</returns>
public static uint? TryGetUintProperty(string path, PropertyKey key)
{
using DisposablePropertyStore propertyStore = GetPropertyStoreFromPath(path);
return propertyStore.TryGetUInt(key);
}
/// <summary>
/// Gets a ulong type value from PropertyStore from the given item.
/// </summary>
@@ -49,6 +38,28 @@ namespace Peek.Common.Helpers
return propertyStore.TryGetString(key);
}
/// <summary>
/// Gets Size composed of weight (uint) and height (uint) from PropertyStore from the given item.
/// </summary>
/// <param name="path">The file/folder path</param>
/// <param name="widthKey">The property key for width</param>
/// <param name="heightKey">The property key for height</param>
/// <returns>a nullable string</returns>
public static Size? TryGetUintSizeProperty(string path, PropertyKey widthKey, PropertyKey heightKey)
{
Size? size = null;
using DisposablePropertyStore propertyStore = GetPropertyStoreFromPath(path);
uint? width = propertyStore.TryGetUInt(widthKey);
uint? height = propertyStore.TryGetUInt(heightKey);
if (width != null && height != null)
{
size = new Size((float)width, (float)height);
}
return size;
}
/// <summary>
/// Gets a IPropertyStore interface (wrapped in DisposablePropertyStore) from the given path.
/// </summary>
@@ -73,7 +84,7 @@ namespace Peek.Common.Helpers
if (hr != 0)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "GetPropertyStore returned hresult={0}", hr));
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "GetPropertyStore returned hresult={0}, errorMessage={1}", hr, Marshal.GetExceptionForHR(hr)!.Message));
}
return new DisposablePropertyStore((IPropertyStore)Marshal.GetObjectForIUnknown(ppPropertyStore));

View File

@@ -5,7 +5,6 @@
using System;
using System.Globalization;
using System.Threading.Tasks;
using Peek.Common.Extensions;
using Peek.Common.Helpers;
using Windows.Storage;
@@ -39,10 +38,6 @@ namespace Peek.Common.Models
public string Path { get; init; }
public uint? Width => PropertyStoreHelper.TryGetUintProperty(Path, PropertyKey.ImageHorizontalSize);
public uint? Height => PropertyStoreHelper.TryGetUintProperty(Path, PropertyKey.ImageVerticalSize);
public ulong FileSizeBytes => PropertyStoreHelper.TryGetUlongProperty(Path, PropertyKey.FileSizeBytes) ?? 0;
public string FileType => PropertyStoreHelper.TryGetStringProperty(Path, PropertyKey.FileType) ?? string.Empty;

View File

@@ -61,5 +61,7 @@ namespace Peek.Common.Models
public static readonly PropertyKey ImageVerticalSize = new PropertyKey(new Guid(0x6444048F, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03), 4);
public static readonly PropertyKey FileSizeBytes = new PropertyKey(new Guid(0xb725f130, 0x47ef, 0x101a, 0xa5, 0xf1, 0x02, 0x60, 0x8c, 0x9e, 0xeb, 0xac), 12);
public static readonly PropertyKey FileType = new PropertyKey(new Guid(0xd5cdd502, 0x2e9c, 0x101b, 0x93, 0x97, 0x08, 0x00, 0x2b, 0x2c, 0xf9, 0xae), 26);
public static readonly PropertyKey FrameWidth = new PropertyKey(new Guid(0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03), 3);
public static readonly PropertyKey FrameHeight = new PropertyKey(new Guid(0x64440491, 0x4C8B, 0x11D1, 0x8B, 0x70, 0x08, 0x00, 0x36, 0xB1, 0x1A, 0x03), 4);
}
}