[BUG] 6.0.1 MedialElement doesn't display / load embedded source
Is there an existing issue for this?
- [x] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [x] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
Hi, I try to use MediaElement component in my project. To implement it, I follow this procedure but it doesn't work with embedded resources. The video isn't loaded and I have this error in the Debug console:
MediaManager: Error: SourceNotSupported, Error code: Value does not fall within the expected range.
If I use remote resource or file system resource (with absolute uri), it works and the video is displayed.
Expected Behavior
The video should be displayed
Steps To Reproduce
- Open the solution in the reproduction project repository
- Launch the application
- You have two MediaElement a. One with URI source => Video is displayed b. One with embedded source => Video isn't load
Link to public reproduction project repository
https://github.com/jeanbeziaud-bib/MediaElementEmbeddedSource
Environment
- CommunityToolkit.Maui.MediaElement: 6.0.1
- OS: Windows 10 Build 10.0.19041.0
- .NET MAUI: 9.0.50
Anything else?
I have maybe forgotten something in the procedure but I don't know what.
The repo is empty and has no content. Can you upload a sample please.
The repo is empty and has no content. Can you upload a sample please.
Sorry @ne0rrmatrix for the mistake :/ It is fixed
Ohhh I tested with .net 8 version and it works :/ I update my repository with .net 8 project.
Works with:
- CommunityToolkit.Maui.MediaElement: 4.1.2
- OS: Windows 10 Build 10.0.19041.0
- .NET MAUI: 8.0.100
Hi,
I've checked with the samples from the github repository of CommunityToolkit.Maui, and it works with .net9.
I've created a project following the official documentation and I've managed to make a project work for macosx, ios and android... but not windows.
I've then played spot the difference with a new fresh maui project and the samples from communitytoolkit, and found that I needed to change the commandName attribute in launchSettings.json from Project to MsixPackage and remove the line <WindowsPackageType>None</WindowsPackageType> from the csproj. Then it worked for windows and .net9.
But there is no mention of that in the documentation. Maybe I'm wrong, maybe it's just a clue...
Can you add this line to an <ItemGroup>
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
Thank you for your feedback.
I had the same problem thant @jeanbeziaud-bib and this line was here from the beginning. My videos and sounds are MauiAsset. This is really the modification of launchSettings.json and the csproj (<WindowsPackagaType/>) that fixed it, also it was working like a charm in .net8 without modifying the json file. The <WindowsPackagaType/> line was added by the .net9 template for Maui App.
Hi, I've checked with the samples from the github repository of CommunityToolkit.Maui, and it works with .net9. I've created a project following the official documentation and I've managed to make a project work for macosx, ios and android... but not windows. I've then played spot the difference with a new fresh maui project and the samples from communitytoolkit, and found that I needed to change the
commandNameattribute in launchSettings.json fromProjecttoMsixPackageand remove the line<WindowsPackageType>None</WindowsPackageType>from the csproj. Then it worked for windows and .net9. But there is no mention of that in the documentation. Maybe I'm wrong, maybe it's just a clue...
It works on my reproduction example :)
But I think we have to update MediaElement to take into account the case when the WindowsPackagaType is setted to none. Or update the documentation to explain to remove it.
I checked FileSystem code and I saw it uses a different way to access to file if the application is packaged or not. Exemple:
https://github.com/dotnet/maui/blob/b2b2191462463e5239184b0a47ec0d0fe2d07e7d/src/Essentials/src/FileSystem/FileSystem.uwp.cs
Or in FileSystemUtil
https://github.com/dotnet/maui/blob/b2b2191462463e5239184b0a47ec0d0fe2d07e7d/src/Essentials/src/FileSystem/FileSystemUtils.uwp.cs
This classes usage is described in this documentation
We have maybe to update MediaElement to specific the source according if the application is packaged or not.
I just tested using our sample app and can confirm running as unpackaged it will not load local resources correctly. I am going to look at this today.
Can you test this PR and see if it fixes your issue? https://github.com/CommunityToolkit/Maui/pull/2609
Can you test this PR and see if it fixes your issue? #2609
Hi @ne0rrmatrix , I tested it by creating local package nuget with your code. It is fixed :) I tested for the both case: packaged and unpackaged mode.
Thank you very much for your contribution :)
everytime i use MAUI to do something on windows is always anb headache :( Thank you for your PR, it seems to fix the issue. i hope one day it will be merged!
Btw, in the meantime i'm using this ugly workaround for my unpackaged app
private async Task PrepareVideoFile()
{
var name = "video.mp4";
var dest = Path.Combine(FileSystem.CacheDirectory, name);
if (!File.Exists(dest))
{
await using var src = await FileSystem.OpenAppPackageFileAsync(name);
await using var dst = File.Create(dest);
await src.CopyToAsync(dst);
}
MediaElement.Source = MediaSource.FromFile(dest);
MediaElement.ShouldAutoPlay = true;
}
video.mp4 is inside Resources\Raw\
It's a hack, it's not pretty but it works :)