Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4e284d5
Fix media element in windows where playing resource mediasource does …
ne0rrmatrix Apr 1, 2025
482036c
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Apr 5, 2025
d5de1f1
Merge branch 'main' into FixResourceMediaSource
TheCodeTraveler Apr 12, 2025
515c410
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix May 4, 2025
d1707b6
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix May 7, 2025
3063cf3
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix May 27, 2025
11271f2
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix May 29, 2025
e71d679
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jun 3, 2025
6e6e226
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jun 8, 2025
965edd5
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jun 20, 2025
9fda0f7
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jun 25, 2025
df5630c
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jul 3, 2025
679c1cc
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jul 3, 2025
ce973df
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jul 4, 2025
7ae8f5f
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jul 8, 2025
9c69440
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Jul 30, 2025
05695fc
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Aug 3, 2025
a32ab52
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Aug 26, 2025
ab783ef
Merge branch 'main' into FixResourceMediaSource
ne0rrmatrix Sep 6, 2025
3be2903
Remove Unused Code
TheCodeTraveler Sep 6, 2025
dbbe7fb
`dotnet format`
TheCodeTraveler Sep 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Windows.ApplicationModel;

namespace CommunityToolkit.Maui.Extensions;

// Since MediaElement can't access .NET MAUI internals we have to copy this code here
// https://github.com/dotnet/maui/blob/main/src/Essentials/src/AppInfo/AppInfo.uwp.cs
static class AppPackageService
{
static readonly Lazy<bool> isPackagedAppHolder = new(() =>
{
try
{
if (Package.Current is not null)
{
return true;
}
}
catch
{
// no-op
}

return false;
});

static readonly Lazy<string> fullAppPackageFilePathHolder = new(() =>
{
return IsPackagedApp
? Package.Current.InstalledLocation.Path
: AppContext.BaseDirectory;
});

/// <summary>
/// Gets if this app is a packaged app.
/// </summary>
public static bool IsPackagedApp => isPackagedAppHolder.Value;


/// <summary>
/// Gets full application path.
/// </summary>
public static string FullAppPackageFilePath => fullAppPackageFilePathHolder.Value;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Numerics;
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.Views;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -301,7 +302,13 @@ protected virtual async partial ValueTask PlatformUpdateSource()
}
else if (MediaElement.Source is ResourceMediaSource resourceMediaSource)
{
string path = "ms-appx:///" + resourceMediaSource.Path;
if (string.IsNullOrWhiteSpace(resourceMediaSource.Path))
{
Logger.LogInformation("ResourceMediaSource Path is null or empty");
return;
}

string path = GetFullAppPackageFilePath(resourceMediaSource.Path);
if (!string.IsNullOrWhiteSpace(path))
{
Player.Source = WinMediaSource.CreateFromUri(new Uri(path));
Expand Down Expand Up @@ -352,6 +359,16 @@ protected virtual void Dispose(bool disposing)
}
}

static string GetFullAppPackageFilePath(in string filename)
{
ArgumentNullException.ThrowIfNull(filename);

var normalizedFilename = NormalizePath(filename);
return Path.Combine(AppPackageService.FullAppPackageFilePath, normalizedFilename);

static string NormalizePath(string filename) => filename.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
}

static bool IsZero<TValue>(TValue numericValue) where TValue : INumber<TValue>
{
return TValue.IsZero(numericValue);
Expand Down
Loading