Maui: [BUG] Setting MediaElement.Source to an embedded video does not work? No matter how it is set?
Is there an existing issue for this?
- I have searched the existing issues
Did you read the “Reporting a bug” section on Contributing file?
- 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
According to the documentation, one should be able to play an embedded video as per the following:
- To enable a media file for playback from the local resources add the file to the Resources/Raw folder of you .NET MAUI project. When a file is added in the root, the URI would be embed://MyFile.mp4.
- In code, please use MediaSource.FromResource() and MediaSource.FromFile() respectively. Using these methods, you can omit the the embed:// and filesystem:// prefixes. The rest of the path should be the same.
However, this does not work at all for an embedded Resource video. I am able to successfully play videos from a URL as follows:
MediaElement mediaElement = new();
mediaElement.Source = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
mediaElement.Play();
I am also able to play files in Windows build from a direct local file path as follows:
MediaElement mediaElement = new();
mediaElement.Source = MediaSource.FromFile("H:\\filePath\\BigBuckBunny.mp4");
mediaElement.Play();
However, no matter what I try, I cannot get a MediaSource.FromResource()
to work. I have placed the video in the general Resources/Raw
folder as requested:
I have also set it as an embedded resource:
And if I run the following code to output all embedded resources, I get as follows:
private void debugResources() {
foreach (string currentResource in System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()) {
Debug.WriteLine(currentResource);
}
}
Output: MauiBuild.Resources.Raw.BigBuckBunny.mp4
showing it is being embedded in the project.
Yet trying to run the video with any of the following for source does not work:
mediaElement.Source = MediaSource.FromResource("MauiBuild.Resources.Raw.BigBuckBunny.mp4");
mediaElement.Source = MediaSource.FromResource("BigBuckBunny.mp4");
mediaElement.Source = new Uri("embed://MauiBuild.Resources.Raw.BigBuckBunny.mp4");
mediaElement.Source = new Uri("embed://BigBuckBunny.mp4");
Should not one of these methods work as suggested by documentation?
Expected Behavior
At least one of the attempted methods to set the mediaElement.Source
from the embedded resource should work.
Steps To Reproduce
-
Create new Maui project in Visual Studio 2022 using .NET 7.0 by File > New
-
Add Maui Community Toolkit and MediaElement packages
-
Download video from
https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
, put in commonResources\Raw
folder with properties set to Embedded Resource. -
Create anywhere in page and it will play:
MediaElement mediaElement = new();
mediaElement.Source = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";
mediaElement.Play();
- Try to do the same but set Source to the Embedded video in
Resources\Raw
using any of the above methods and nothing will play.
Link to public reproduction project repository
https://github.com/jonmdev/MediaElement-Resource-Bug
Environment
- .NET MAUI CommunityToolkit: 5.3.0
- .NET Maui MediaElement 2.0.0
- OS: Windows 10, Android
- .NET MAUI: 7.0
Anything else?
No response
About this issue
- Original URL
- State: open
- Created 9 months ago
- Comments: 17 (9 by maintainers)
The detail above your comment shows the PR that has fixed the issue. We just need to get a release out with the fix in