Skip to content

Commit b0fa9a8

Browse files
authored
Merge branch 'main' into fix/camera-provider-refresh
2 parents c0d810b + 49a1241 commit b0fa9a8

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
xcode-version: latest-stable
4040

4141
- name: Install Latest Version of .NET, v${{ env.LATEST_NET_VERSION }}
42-
uses: actions/setup-dotnet@v4
42+
uses: actions/setup-dotnet@v5
4343
with:
4444
dotnet-version: ${{ env.LATEST_NET_VERSION }}
4545
dotnet-quality: 'ga'

.github/workflows/dotnet-build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
xcode-version: latest-stable
6969

7070
- name: Install Latest .NET SDK, v${{ env.LATEST_NET_VERSION }}
71-
uses: actions/setup-dotnet@v4
71+
uses: actions/setup-dotnet@v5
7272
with:
7373
dotnet-version: ${{ env.LATEST_NET_VERSION }}
7474
dotnet-quality: 'ga'
@@ -142,7 +142,7 @@ jobs:
142142
xcode-version: ${{ env.CommunityToolkitLibrary_Xcode_Version }}
143143

144144
- name: Install .NET SDK v${{ env.TOOLKIT_NET_VERSION }}
145-
uses: actions/setup-dotnet@v4
145+
uses: actions/setup-dotnet@v5
146146
with:
147147
dotnet-version: ${{ env.TOOLKIT_NET_VERSION }}
148148
dotnet-quality: 'ga'
@@ -270,7 +270,7 @@ jobs:
270270

271271
steps:
272272
- name: Install .NET SDK v${{ env.TOOLKIT_NET_VERSION }}
273-
uses: actions/setup-dotnet@v4
273+
uses: actions/setup-dotnet@v5
274274
with:
275275
dotnet-version: ${{ env.TOOLKIT_NET_VERSION }}
276276
dotnet-quality: 'ga'
@@ -342,7 +342,7 @@ jobs:
342342

343343
steps:
344344
- name: Install .NET SDK
345-
uses: actions/setup-dotnet@v4
345+
uses: actions/setup-dotnet@v5
346346
with:
347347
dotnet-version: ${{ env.TOOLKIT_NET_VERSION }}
348348
dotnet-quality: 'ga'
@@ -370,7 +370,7 @@ jobs:
370370

371371
steps:
372372
- name: Install .NET SDK
373-
uses: actions/setup-dotnet@v4
373+
uses: actions/setup-dotnet@v5
374374
with:
375375
dotnet-version: ${{ env.TOOLKIT_NET_VERSION }}
376376
dotnet-quality: 'ga'
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Windows.ApplicationModel;
2+
3+
namespace CommunityToolkit.Maui.Extensions;
4+
5+
// Since MediaElement can't access .NET MAUI internals we have to copy this code here
6+
// https://github.com/dotnet/maui/blob/main/src/Essentials/src/AppInfo/AppInfo.uwp.cs
7+
static class AppPackageService
8+
{
9+
static readonly Lazy<bool> isPackagedAppHolder = new(() =>
10+
{
11+
try
12+
{
13+
if (Package.Current is not null)
14+
{
15+
return true;
16+
}
17+
}
18+
catch
19+
{
20+
// no-op
21+
}
22+
23+
return false;
24+
});
25+
26+
static readonly Lazy<string> fullAppPackageFilePathHolder = new(() =>
27+
{
28+
return IsPackagedApp
29+
? Package.Current.InstalledLocation.Path
30+
: AppContext.BaseDirectory;
31+
});
32+
33+
/// <summary>
34+
/// Gets if this app is a packaged app.
35+
/// </summary>
36+
public static bool IsPackagedApp => isPackagedAppHolder.Value;
37+
38+
39+
/// <summary>
40+
/// Gets full application path.
41+
/// </summary>
42+
public static string FullAppPackageFilePath => fullAppPackageFilePathHolder.Value;
43+
}

src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using System.Numerics;
33
using CommunityToolkit.Maui.Core.Primitives;
4+
using CommunityToolkit.Maui.Extensions;
45
using CommunityToolkit.Maui.Views;
56
using Microsoft.Extensions.Logging;
67
using Microsoft.UI.Xaml.Controls;
@@ -301,7 +302,13 @@ protected virtual async partial ValueTask PlatformUpdateSource()
301302
}
302303
else if (MediaElement.Source is ResourceMediaSource resourceMediaSource)
303304
{
304-
string path = "ms-appx:///" + resourceMediaSource.Path;
305+
if (string.IsNullOrWhiteSpace(resourceMediaSource.Path))
306+
{
307+
Logger.LogInformation("ResourceMediaSource Path is null or empty");
308+
return;
309+
}
310+
311+
string path = GetFullAppPackageFilePath(resourceMediaSource.Path);
305312
if (!string.IsNullOrWhiteSpace(path))
306313
{
307314
Player.Source = WinMediaSource.CreateFromUri(new Uri(path));
@@ -352,6 +359,16 @@ protected virtual void Dispose(bool disposing)
352359
}
353360
}
354361

362+
static string GetFullAppPackageFilePath(in string filename)
363+
{
364+
ArgumentNullException.ThrowIfNull(filename);
365+
366+
var normalizedFilename = NormalizePath(filename);
367+
return Path.Combine(AppPackageService.FullAppPackageFilePath, normalizedFilename);
368+
369+
static string NormalizePath(string filename) => filename.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
370+
}
371+
355372
static bool IsZero<TValue>(TValue numericValue) where TValue : INumber<TValue>
356373
{
357374
return TValue.IsZero(numericValue);

0 commit comments

Comments
 (0)