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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="XamarinAudioPlayer.Forms.kk" Version="2.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="XamarinAudioPlayer.Forms.kk" Version="2.1.1" />
                    
Directory.Packages.props
<PackageReference Include="XamarinAudioPlayer.Forms.kk" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add XamarinAudioPlayer.Forms.kk --version 2.1.1
                    
#r "nuget: XamarinAudioPlayer.Forms.kk, 2.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package XamarinAudioPlayer.Forms.kk@2.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=XamarinAudioPlayer.Forms.kk&version=2.1.1
                    
Install as a Cake Addin
#tool nuget:?package=XamarinAudioPlayer.Forms.kk&version=2.1.1
                    
Install as a Cake Tool

#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:

  1. Add the XamarinAudioPlayer.Forms.kk NuGet package to your MAUI project.
  2. Add the your mp3 file inside the Resource → Raw folder of your MAUI project.
  3. Create a new page or use an existing one where you want to display the audio player.
  4. Inherit the XamarinAudioPlayerLibary in your xaml namespace, for example:
    xmlns:cs="clr-namespace:XamarinAudioPlayerLibary.View;assembly=XamarinAudioPlayerLibary"
    
  5. 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:

  1. Add the XamarinAudioPlayer.Forms.kk NuGet package to your MAUI project.
  2. Add the your mp3 file inside the Resource → Raw folder of your MAUI project.
  3. Create a new page or use an existing one where you want to display the audio player.
  4. Inherit the XamarinAudioPlayerLibary in your xaml namespace, for example:
    xmlns:cs="clr-namespace:XamarinAudioPlayerLibary.View;assembly=XamarinAudioPlayerLibary"
    
  5. In your xamal add the slider,play, pause, stop button and other controls as per your design.
  6. In your code behind, you can use the KKAudioFile class to control the audio playback. For example:
  7. 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.

  1. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.1 74 8/9/2025
1.0.0 884 7/24/2019

- 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.