I need to play a simple beep sound.
After a lot of research this seems to be one of the best and easiest ways.
Accepted answer here.
how to play an audio file – .NET MAUI
and
https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/views/mediaelement?tabs=windows
I created a new project and complied it.
But when I try to add the reference to
CommunityToolkit.Maui.MediaElement (version 4.10)
it doesn’t install.
https://www.nuget.org/packages/CommunityToolkit.Maui.MediaElement
The add reference finds it and acts like it installs it.
The output windows shows this.
Restoring packages for C:ProjectsTestAppTestAppTestApp.csproj...
CACHE https://api.nuget.org/v3/vulnerabilities/index.json
CACHE https://api.nuget.org/v3-vulnerabilities/2024.08.29.05.32.17/vulnerability.base.json
CACHE https://api.nuget.org/v3-vulnerabilities/2024.08.29.05.32.17/2024.09.04.05.32.39/vulnerability.update.json
NU1605: Warning As Error: Detected package downgrade: Microsoft.Maui.Controls from 8.0.71 to 8.0.61. Reference the package directly from the project to select a different version.
TestApp -> CommunityToolkit.Maui.MediaElement 4.1.0 -> Microsoft.Maui.Controls (>= 8.0.71)
TestApp -> Microsoft.Maui.Controls (>= 8.0.61)
Package restore failed. Rolling back package changes for 'TestApp'.
Time Elapsed: 00:00:01.3859624
========== Finished ==========
I guess this is the problem. “Reference the package directly from the project to select a different version.”
I found this “NuGet Warning NU1605” but still have no idea what to do to resolve this.
https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1605
How do I get this package to install or is there a better way to play a simple beep sound?
private void OnButtonClicked(object sender, EventArgs e)
{
var instance = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
Android.Net.Uri uri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
Ringtone rt = RingtoneManager.GetRingtone(instance.ApplicationContext, uri);
rt.Play();
}
Also refer the media element document: https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/views/mediaelement?tabs=android
5