File tree Expand file tree Collapse file tree 4 files changed +54
-160
lines changed
Expand file tree Collapse file tree 4 files changed +54
-160
lines changed Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -308,8 +308,7 @@ protected virtual async partial ValueTask PlatformUpdateSource()
308308 return ;
309309 }
310310
311- // To test this run app as unpackaged and packaged.
312- string path = FileSystemUtils . PlatformGetFullAppPackageFilePath ( resourceMediaSource . Path ) ;
311+ string path = GetFullAppPackageFilePath ( resourceMediaSource . Path ) ;
313312 if ( ! string . IsNullOrWhiteSpace ( path ) )
314313 {
315314 Player . Source = WinMediaSource . CreateFromUri ( new Uri ( path ) ) ;
@@ -360,6 +359,16 @@ protected virtual void Dispose(bool disposing)
360359 }
361360 }
362361
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+
363372 static bool IsZero < TValue > ( TValue numericValue ) where TValue : INumber < TValue >
364373 {
365374 return TValue . IsZero ( numericValue ) ;
You can’t perform that action at this time.
0 commit comments