Euphiny.Maui.Audio.Player
1.3.1
dotnet add package Euphiny.Maui.Audio.Player --version 1.3.1
NuGet\Install-Package Euphiny.Maui.Audio.Player -Version 1.3.1
<PackageReference Include="Euphiny.Maui.Audio.Player" Version="1.3.1" />
<PackageVersion Include="Euphiny.Maui.Audio.Player" Version="1.3.1" />
<PackageReference Include="Euphiny.Maui.Audio.Player" />
paket add Euphiny.Maui.Audio.Player --version 1.3.1
#r "nuget: Euphiny.Maui.Audio.Player, 1.3.1"
#:package Euphiny.Maui.Audio.Player@1.3.1
#addin nuget:?package=Euphiny.Maui.Audio.Player&version=1.3.1
#tool nuget:?package=Euphiny.Maui.Audio.Player&version=1.3.1
Maui.Audio.Player
A package which allows you to play audio in your MAUI application. Either use it as a standalone solution or integrate with platform-specific session display implementations such as iOS's NowPlayingInfoCenter
and Android's MediaSession
.
This package is still in development. Currently, this package is stable and ready to use, but it lacks some nice-to-have features like seeking the audio through the session display notification. If you need such features, you're welcome to submit an issue or PR and I'll take a look into it.
Features
- Play audio through HTTP streaming.
- Integrate with
NowPlayingInfoCenter
orMediaSession
. - Separated concerns, pick and choose what you need.
Installation
Maui.Audio.Player
can be found on NuGet. Install it by using dotnet add package Euphiny.Maui.Audio.Player
.
Usage
This package provides 3 services, these are:
AudioPlayer
, used to actually play audio using the native implementation.MediaInfoManager
, used to set and update the session details usingNowPlayingInfoCenter
orMediaSession
.AudioPlayerController
, the service which combines theAudioPlayer
and theMediaInfoManager
together to provide an all-in-one api.
To add these services to the dependency container, call UseMauiAudioPlayer
in your MauiAppBuilderExtensions.cs
file. It is advised to create an AudioPlayerOptions object and use it as an argument to initialize the audio player. Currently only the IconResource is requested on Android, which is used by the media notification as app icon.
public static MauiApp CreateMauiApp()
{
var audioPlayerOptions = new AudioPlayerOptions();
#if ANDROID
audioPlayerOptions.IconResource = Resource.Drawable.Icon;
#endif
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.UseMauiAudioPlayer(audioPlayerOptions)
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
return builder.Build();
}
It is than possible to take IAudioPlayerController
as constructor argument and use it to start playing audio:
public void PlayAudio()
{
var url = "https://song-url.com";
var imageUrl = "https://image-url.com";
var duration = TimeSpan.FromSeconds(150);
var artists = new List<string>()
{
"Artist 1",
"Artist 2"
};
var mediaInfo = new MediaInfo("Name of the song", string.Join(", ", artists), duration, imageUrl);
_audioPlayerController.Start(url, mediaInfo);
}
The AudioPlayerController
exposes other methods besides the Start
method:
Play()
, to tell the player to start playing audio, is called internally when starting the player.Pause()
, to pause the playerSeek()
, to move the current position of the player backwards or forwards.
Furthermore, the PlayerInfo
property holds the current state of the player, information such as duration, progress and whether the player is playing any audio can be found here.
When the player is done playing the audio stream, the PlaybackEnded
event is fired.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-android34.0 is compatible. net8.0-browser was computed. net8.0-ios was computed. net8.0-ios18.0 is compatible. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Maui.Controls (>= 8.0.100)
-
net8.0-android34.0
- Microsoft.Maui.Controls (>= 8.0.100)
- Xamarin.AndroidX.Media (>= 1.7.0.10)
-
net8.0-ios18.0
- Microsoft.Maui.Controls (>= 8.0.100)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.