From e0e9cea53fb9c610d8a229aab633da1f382c618c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 05:01:25 +0000 Subject: [PATCH 1/5] Initial plan for issue From 2907a63c7ae7bdfb42e124e5eaafa7a55fab429b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 05:06:00 +0000 Subject: [PATCH 2/5] Enhance MP4 video playback for better codec support Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com> --- .../Previewers/MediaPreviewer/VideoPreviewer.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs b/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs index 0a80661bfa65..3e4099026332 100644 --- a/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs +++ b/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs @@ -102,7 +102,16 @@ await Dispatcher.RunOnUiThread(() => { cancellationToken.ThrowIfCancellationRequested(); - Preview = MediaSource.CreateFromStorageFile(storageFile); + // For MP4 files, use CreateFromUri approach which provides better codec support + if (Item.Extension.Equals(".mp4", StringComparison.OrdinalIgnoreCase)) + { + var fileUri = new Uri(storageFile.Path); + Preview = MediaSource.CreateFromUri(fileUri); + } + else + { + Preview = MediaSource.CreateFromStorageFile(storageFile); + } }); }); } From d4f52d582b5fe1a503cc812877584a4a32cda937 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 05:07:38 +0000 Subject: [PATCH 3/5] Add clarifying comment about MP4 video fix Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com> --- .../Previewers/MediaPreviewer/VideoPreviewer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs b/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs index 3e4099026332..bbefa5b812a0 100644 --- a/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs +++ b/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs @@ -103,6 +103,7 @@ await Dispatcher.RunOnUiThread(() => cancellationToken.ThrowIfCancellationRequested(); // For MP4 files, use CreateFromUri approach which provides better codec support + // This helps with MP4 files that would otherwise only play audio without showing video if (Item.Extension.Equals(".mp4", StringComparison.OrdinalIgnoreCase)) { var fileUri = new Uri(storageFile.Path); From f0c7cebf542aa31521ef0e6404f091e24c638bab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 07:17:01 +0000 Subject: [PATCH 4/5] Add codec availability check for video playback Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com> --- .../peek/Peek.FilePreviewer/FilePreview.xaml | 9 ++++ .../Peek.FilePreviewer/FilePreview.xaml.cs | 9 ++++ .../Previewers/Interfaces/IVideoPreviewer.cs | 2 + .../MediaPreviewer/VideoPreviewer.cs | 44 +++++++++++++++---- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml index c3bbe50c61fd..e895b85388e0 100644 --- a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml +++ b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml @@ -60,6 +60,15 @@ + + LoadVideoAsync(CancellationToken cancellationToken) cancellationToken.ThrowIfCancellationRequested(); var storageFile = await Item.GetStorageItemAsync() as StorageFile; - - await Dispatcher.RunOnUiThread(() => + bool success = false; + + await Dispatcher.RunOnUiThread(async () => { cancellationToken.ThrowIfCancellationRequested(); - // For MP4 files, use CreateFromUri approach which provides better codec support - // This helps with MP4 files that would otherwise only play audio without showing video - if (Item.Extension.Equals(".mp4", StringComparison.OrdinalIgnoreCase)) + try { - var fileUri = new Uri(storageFile.Path); - Preview = MediaSource.CreateFromUri(fileUri); + // For MP4 files, try CreateFromUri first as it provides better codec support + // This helps with MP4 files that would otherwise only play audio without showing video + if (Item.Extension.Equals(".mp4", StringComparison.OrdinalIgnoreCase)) + { + try + { + var fileUri = new Uri(storageFile.Path); + Preview = MediaSource.CreateFromUri(fileUri); + success = true; + } + catch (Exception) + { + // If CreateFromUri fails, fall back to CreateFromStorageFile + Preview = MediaSource.CreateFromStorageFile(storageFile); + success = true; + } + } + else + { + Preview = MediaSource.CreateFromStorageFile(storageFile); + success = true; + } } - else + catch (Exception ex) { - Preview = MediaSource.CreateFromStorageFile(storageFile); + // If all methods fail, it's likely due to missing codecs + ErrorMessage = "This video requires codecs that are not installed on your system"; + success = false; } }); + + return success; }); } From 78f45b05febcd2051cad44fbfddb7d4a14b4986d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 07:29:59 +0000 Subject: [PATCH 5/5] Implement codec detection for video playback Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com> --- .../MediaPreviewer/VideoPreviewer.cs | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs b/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs index 1ede280ae914..f9b8b3f9de5d 100644 --- a/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs +++ b/src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/VideoPreviewer.cs @@ -16,6 +16,8 @@ using Peek.FilePreviewer.Previewers.Interfaces; using Windows.Foundation; using Windows.Media.Core; +using Windows.Media.MediaProperties; +using Windows.Media.Transcoding; using Windows.Storage; namespace Peek.FilePreviewer.Previewers @@ -93,6 +95,40 @@ await Dispatcher.RunOnUiThread(async () => }); } + private async Task IsCodecSupportedAsync(StorageFile file) + { + try + { + // Create a MediaEncodingProfile from the file to check codec compatibility + var profile = await MediaEncodingProfile.CreateFromFileAsync(file); + + // Use MediaTranscoder to check if the file can be transcoded (which indicates codec support) + var transcoder = new MediaTranscoder + { + AlwaysReencode = false, + HardwareAccelerationEnabled = true, + }; + + // We're not actually transcoding, just checking if we could + // Use the same profile as input and output for this test + var prepareResult = await transcoder.PrepareFileTranscodeAsync(file, file, profile); + + // If we can't transcode with hardware acceleration, try without it + if (!prepareResult.CanTranscode && prepareResult.FailureReason == TranscodeFailureReason.HardwareNotAvailable) + { + transcoder.HardwareAccelerationEnabled = false; + prepareResult = await transcoder.PrepareFileTranscodeAsync(file, file, profile); + } + + return prepareResult.CanTranscode; + } + catch (Exception) + { + // If the profile creation fails, we assume the codec is not supported + return false; + } + } + private Task LoadVideoAsync(CancellationToken cancellationToken) { return TaskExtension.RunSafe(async () => @@ -102,12 +138,23 @@ private Task LoadVideoAsync(CancellationToken cancellationToken) var storageFile = await Item.GetStorageItemAsync() as StorageFile; bool success = false; + // First, check if the codec is supported for this file + bool isCodecSupported = await IsCodecSupportedAsync(storageFile); + await Dispatcher.RunOnUiThread(async () => { cancellationToken.ThrowIfCancellationRequested(); try { + if (!isCodecSupported) + { + // If codec is not supported, show error message immediately + ErrorMessage = "This video requires codecs that are not installed on your system"; + success = false; + return; + } + // For MP4 files, try CreateFromUri first as it provides better codec support // This helps with MP4 files that would otherwise only play audio without showing video if (Item.Extension.Equals(".mp4", StringComparison.OrdinalIgnoreCase)) @@ -131,7 +178,7 @@ await Dispatcher.RunOnUiThread(async () => success = true; } } - catch (Exception ex) + catch (Exception) { // If all methods fail, it's likely due to missing codecs ErrorMessage = "This video requires codecs that are not installed on your system";