XamarinAudioPlayer.Forms.kk
2.1.1
dotnet add package XamarinAudioPlayer.Forms.kk --version 2.1.1
NuGet\Install-Package XamarinAudioPlayer.Forms.kk -Version 2.1.1
<PackageReference Include="XamarinAudioPlayer.Forms.kk" Version="2.1.1" />
<PackageVersion Include="XamarinAudioPlayer.Forms.kk" Version="2.1.1" />
<PackageReference Include="XamarinAudioPlayer.Forms.kk" />
paket add XamarinAudioPlayer.Forms.kk --version 2.1.1
#r "nuget: XamarinAudioPlayer.Forms.kk, 2.1.1"
#:package XamarinAudioPlayer.Forms.kk@2.1.1
#addin nuget:?package=XamarinAudioPlayer.Forms.kk&version=2.1.1
#tool nuget:?package=XamarinAudioPlayer.Forms.kk&version=2.1.1
#XamarinAudioPlayer.Forms.kk developed using MAUI.
Overview
XamarinAudioPlayer.Forms.kk is a MAUI This library supports playing audio files from both the app's bundled resources and the device's local file system.
Features
- Read Audio files from the app's bundled resources.
- Read Audio files from the device's local file system.
- Cross-platform support (Android & iOS).
- Smooth UI experience with MAUI.
- It has predefined Audio Player Controls for easy integration.
- It has progress control to show the audio file play time.
- It has play, pause, stop to control for the audio.
DOCUEMNTAION
To Implement the predefined Audio Player View, you can follow the steps below:
- Add the
XamarinAudioPlayer.Forms.kk
NuGet package to your MAUI project. - Add the your mp3 file inside the Resource → Raw folder of your MAUI project.
- Create a new page or use an existing one where you want to display the audio player.
- Inherit the
XamarinAudioPlayerLibary
in your xaml namespace, for example:xmlns:cs="clr-namespace:XamarinAudioPlayerLibary.View;assembly=XamarinAudioPlayerLibary"
- Add this line code in you inside the configure handler handler in maui program.cs file:
.ConfigureMauiHandlers(handlers => { // Register custom handlers if needed handlers.AddHandler(typeof(KKCustomSlider), typeof(XamarinAudioPlayer.KKSliderHandler)); })
5.Add the 'KKAudioPlayerView' control to your XAML page where you want the audio player to appear:
xml <cs:KKAudioPlayerView EndPlayTimeTextColor="Red" CurrentPlayTimeTextColor="Blue" MaximumSliderTrackColor="Green" MinimumSliderTrackColor="LightGreen" EndPlayTimeFontSize ="14" CurrentPlayTimeFontSize="14" PlayImageName="play" PauseImageName="pause" FileType="mp3" AudioName="TestAudioSong" />
To desing the your own Audio Player View, you can use the following steps:
- Add the
XamarinAudioPlayer.Forms.kk
NuGet package to your MAUI project. - Add the your mp3 file inside the Resource → Raw folder of your MAUI project.
- Create a new page or use an existing one where you want to display the audio player.
- Inherit the
XamarinAudioPlayerLibary
in your xaml namespace, for example:xmlns:cs="clr-namespace:XamarinAudioPlayerLibary.View;assembly=XamarinAudioPlayerLibary"
- In your xamal add the slider,play, pause, stop button and other controls as per your design.
- In your code behind, you can use the
KKAudioFile
class to control the audio playback. For example: - Add the following code in your code behind file (e.g., MainPage.xaml.cs):
```csharp
using XamarinAudioPlayerLibary.ViewModel;
#if ANDROID
using XamarinAudioPlayer.Platforms.Android;
#elif IOS
using XamarinAudioPlayer.Platforms.iOS;
#endif
public partial class KKAudioPlayer : ContentPage
{
private KKAudioFile _audioFile;
public KKAudioPlayer()
{
InitializeComponent();
_audioFile = new KKAudioFile();
lblcurrent.Text = "0.0";
SetupAuidoFile();
}
protected override void OnDisappearing()
{
base.OnDisappearing();
if (_audioFile != null)
{
_audioFile.PositionChanged -= Slider_PositionChanged;
// To Remove all the audio setup and event handlers from the memory
_audioFile.RemoveAudioSetup();
}
}
/// <summary>
/// Sets up the audio file with the specified filename and type.
/// </summary>
public void SetupAuidoFile()
{
if (_audioFile != null)
{
//Set the audio file name and type here
_audioFile.SetUpAudio("TestAudioSong", "mp3");
// Subscribe to the PositionChanged event current audio position
_audioFile.PositionChanged += Slider_PositionChanged;
// Get the total playing time of the audio file
lblTotalCount.Text = (string)_audioFile.GetTotalTime();
// Set the total playing time of the audio file as the maximum value of the slider
customSlider.Maximum = Convert.ToDouble(_audioFile.MediaTotalDuration());
}
}
/// <summary>
/// Play button click event handler to start playing the audio file.
/// </summary>
void PlayClick(object sender, System.EventArgs e)
{
if (_audioFile != null)
{
_audioFile.Play();
}
}
/// <summary>
/// Pause button click event handler to pause the audio file playback.
/// </summary>
void PauseClick(object sender, System.EventArgs e)
{
if (_audioFile != null)
_audioFile.Pause();
}
/// <summary>
/// Restart button click event handler to restart the audio file playback.
/// </summary>
void RestartClick(object sender, System.EventArgs e)
{
if (_audioFile != null)
_audioFile.Restart();
lblcurrent.Text = "0.0";
}
}
```
Repository Details
1.Get the full working code from the repository.
- Clone the repository:
git clone https://github.com/kamalkumar1/XamarinFormsAudioplayer/tree/develop
Prerequisites
Before running the project, ensure you have:
- MAUI** installed
- Visual Studio with MAUI development enabled
- Android SDK (for Android development)
- iOS Simulator or device (for iOS development)
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-android34.0 is compatible. net8.0-ios18.0 is compatible. net9.0-android was computed. net9.0-ios was computed. net10.0-android was computed. net10.0-ios was computed. |
-
net8.0-android34.0
- Microsoft.Extensions.Logging.Debug (>= 8.0.1)
- Microsoft.Maui.Controls (>= 8.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 8.0.100)
-
net8.0-ios18.0
- Microsoft.Extensions.Logging.Debug (>= 8.0.1)
- Microsoft.Maui.Controls (>= 8.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 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.
- Read Audio files from the app's bundled resources.
- Read Audio files from the device's local file system.
- Cross-platform support (**Android & iOS**).
- Smooth UI experience with **MAUI**.
- It has predefined Audio Player Controls for easy integration.
- It has progress control to show the audio file play time.
- It has play, pause, stop to control for the audio.