• Stars
    star
    201
  • Rank 194,491 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created about 2 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Plugin.Maui.Audio provides the ability to play audio inside a .NET MAUI application

Plugin.Maui.Audio

Plugin.Maui.Audio provides the ability to play audio inside a .NET MAUI application.

Getting Started

API Usage

Plugin.Maui.Audio provides the AudioManager class that allows for the creation of AudioPlayers. The AudioManager can be used with or without dependency injection.

AudioManager

Dependency Injection

You will first need to register the AudioManager with the MauiAppBuilder following the same pattern that the .NET MAUI Essentials libraries follow.

builder.Services.AddSingleton(AudioManager.Current);

You can then enable your classes to depend on IAudioManager as per the following example.

public class AudioPlayerViewModel
{
    readonly IAudioManager audioManager;

    public AudioPlayerViewModel(IAudioManager audioManager)
    {
        this.audioManager = audioManager;
    }

    public async void PlayAudio()
    {
        var audioPlayer = audioManager.CreatePlayer(await FileSystem.OpenAppPackageFileAsync("ukelele.mp3"));

        audioPlayer.Play();
    }
}

Straight usage

Alternatively if you want to skip using the dependency injection approach you can use the AudioManager.Current property.

public class AudioPlayerViewModel
{
    public async void PlayAudio()
    {
        var audioPlayer = AudioManager.Current.CreatePlayer(await FileSystem.OpenAppPackageFileAsync("ukelele.mp3"));

        audioPlayer.Play();
    }
}

AudioPlayer

Once you have created an AudioPlayer you can interact with it in the following ways:

Events

PlaybackEnded

Raised when audio playback completes successfully.

Properties

Balance

Gets or sets the balance left/right: -1 is 100% left : 0% right, 1 is 100% right : 0% left, 0 is equal volume left/right.

CanSeek

Gets a value indicating whether the position of the loaded audio file can be updated.

CanSetSpeed

Gets a value indicating whether the playback speed can be changed.

CurrentPosition

Gets the current position of audio playback in seconds.

Duration

Gets the length of audio in seconds.

IsPlaying

Gets a value indicating whether the currently loaded audio file is playing.

MaximumSpeed

Gets the minumum speed that is supported on the platform the app is running on that can be set for the Speed property.

MinimumSpeed

Gets the maximum speed that is supported on the platform the app is running on that can be set for the Speed property.

Speed

Gets or sets the speed of the playback. Note: the maximum and minimum value that can be set is dependant on the platform you're running on. Setting a value that is not supported on the platform will gracefully fallback, but will not have the desired result.

To determine the supported minimum and maximum speeds at runtime for that platform you can use MaximumSpeed and MinimumSpeed.

Platform notes:

  • Android: between 0 and 6. Setting the value to 0 will pause playback, playback will not be resumed when incrementing the value again.
  • iOS: between 0.5 and 2.
  • Windows: between 0 and 8. Setting the value to 0 will pause playback, playback will be resumed when incrementing the value again.
Volume

Gets or sets the playback volume 0 to 1 where 0 is no-sound and 1 is full volume.

Loop

Gets or sets whether the player will continuously repeat the currently playing sound.

Methods

Pause()

Pause playback if playing (does not resume).

Play()

Begin playback or resume if paused.

Seek(double position)

Set the current playback position (in seconds).

Stop()

Stop playback and set the current position to the beginning.

Acknowledgements

This project could not have came to be without these projects and people, thank you! <3

SimpleAudioPlayer for Xamarin

Basically this plugin, but then for Xamarin. We have been using this in our Xamarin projects with much joy and ease, so thank you so much Adrian (and contributors!) for that. Find the original project here where we have based our project on and evolved it from there.

The Happy Ukelele Song

As a little sample song we wanted something Hawaii/Maui themed obviously, and we found The Happy Ukelele Song which seems to fit that description. Thank you Stanislav Fomin and AudioHero for making it available.

More Repositories

1

learn-dotnet-maui

A repository filled with resources available to you to start learning or deepen your knowledge about .NET MAUI
392
star
2

FilePicker-Plugin-for-Xamarin-and-Windows

FilePicker Plugin for Xamarin and Windows
C#
156
star
3

MauiFolderPickerSample

Sample code to demonstrate how to implement a folder picker with .NET MAUI
C#
50
star
4

pdfjs

A sample for showing PDF files in a Xamarin.Forms application with pdf.js
JavaScript
32
star
5

Plugin.Maui.ScreenBrightness

Plugin.Maui.ScreenBrightness provides the ability to get or set the screen brightness inside a .NET MAUI application.
C#
30
star
6

XFFCMPushNotificationsSample

Sample code to demonstrate how to implement push notifications in Xamarin.Forms with Firebase Cloud Messaging (FCM)
C#
24
star
7

ZXingSample

Working sample app for a blog post on barcode scanning and generating with ZXing
C#
23
star
8

TravelMonkey

TravelMonkey sample app for the Xamarin + Cognitive Services Crazy Combo Challenge
C#
21
star
9

AirplaneModeProof

This repository contains the sample code for my talk "Creating airplane mode proof Xamarin applications"
C#
20
star
10

XFBackgroundLocationSample

Sample code to demonstrate how to track a devices' background location with Xamarin.Forms
C#
19
star
11

EmbeddedFontsSample

Sample code to show the power of embedded fonts in Xamarin.Forms
C#
18
star
12

Plugin.Maui.ScreenRecording

Plugin.Maui.ScreenRecording provides the ability to record the screen from within your app
C#
18
star
13

MauiZxingBarcodeScannerSample

Sample code to demonstrate how to scan barcodes with ZXing and .NET MAUI
C#
18
star
14

been-pwned

App that leverages the haveibeenpwned.com API by Troy Hunt. This app is available in the App Stores and is used in several of my talks as well as my book Xamarin.Forms Essentials.
C#
16
star
15

MauiShellAppTemplate

.NET MAUI Shell Template
C#
15
star
16

Plugin.Maui.UITestHelpers

A set of helpers to support UI testing your .NET MAUI app and migration from Xamarin.UITest to Appium
C#
15
star
17

XamarinNotifications

The sample app for my blogposts about push notifications with Xamarin.Forms on https://blog.verslu.is
C#
15
star
18

MauiSpeechToTextSample

Sample code to demonstrate how to implement speech-to-text with .NET MAUI
C#
15
star
19

WifiBarcodeSample

Sample code for my article in DotNetCurry magazine on scanning barcodes. In this sample you can generate and scan QR codes that contain a Wi-Fi connection string
C#
15
star
20

MauiSignalRSample

Sample code to demonstrate how to get started with SignalR and .NET MAUI
C#
12
star
21

MauiLocalPushNotificationsSample

Sample code to demonstrate how to work with local push notifications in .NET MAUI
C#
12
star
22

XFDotNetExtensionsDISample

Sample code to demonstrate the use of Microsoft.Extensions.DependencyInjection with Xamarin.Forms
C#
12
star
23

XFUploadFile

Sample code to show how to upload a file from Xamarin.Forms
C#
12
star
24

AkavacheSample

Sample code for my blog post about Akavache
C#
11
star
25

XFSQLiteGettingStartedSample

Sample code to demonstrate how to get started with SQLite in your Xamarin.Forms or .NET MAUI app
C#
11
star
26

MauixUnitTestSample

Sample code to demonstrate how to add a xUnit test project to your .NET MAUI app
C#
11
star
27

MauiLocalizationSample

Sample code to demonstrate how to localize a .NET MAUI application
C#
11
star
28

MauiPlatformCodeDISample

Code to demonstrate how to write platform-specific code with dependency injection in .NET MAUI
C#
11
star
29

MauiCameraMauiSample

Sample code to demonstrate how to work with the Camera.MAUI plugin in .NET MAUI
C#
11
star
30

MauiEncryptedSqliteSample

Sample code to demonstrate how to work with a encrypted SQLite database in .NET MAUI (and Xamarin.Forms)
C#
11
star
31

LottieSample

C#
10
star
32

CustomFontsSample

A sample for showing how to use custom fonts in Android and iOS using Xamarin.Forms
C#
10
star
33

AlternateRowColorSample

Answer to a Stackoverflow question about how to implement an alternate row color in a Xamarin.Forms ListView
C#
10
star
34

MauiMapsSample

Sample code to demonstrate how to work with .NET MAUI Maps
C#
10
star
35

CastRadio

C#
9
star
36

XFUploadFileChunkedSample

Sample code to demonstrate how to upload a file through chuncks enabling cancellation, progress reporting and resuming uploads with Xamarin.Forms and ASP.NET
C#
9
star
37

MauiGithubActionsSample

Sample repository to show you how to build your .NET MAUI app with GitHub actions for Android, iOS, macOS and Windows
C#
9
star
38

MauiCollectionViewGroupingSample

Sample code to demonstrate how to implement grouping with .NET MAUI CollectionView
C#
9
star
39

MauiDesktopFeaturesSample

Sample code to demonstrate desktop features in .NET MAUI
C#
8
star
40

BeenPwned.Api

.NET Wrapper library for the haveibeenpwned.com API
C#
8
star
41

XFAdMobSample

Sample code to demonstrate the implementation of AdMob Ads in Xamarin.Forms
C#
8
star
42

XFScanBarcodeSample

Sample code to demonstrate barcode scanning with ZXing in Xamarin.Forms
C#
8
star
43

DifferentAppIconsSample

Sample code for the blog post: Different app icons for different configurations in Xamarin
C#
8
star
44

LoadXamlSample

Example code for loading XAML into a page and showing it for Xamarin.Forms
C#
7
star
45

MauiGoogleMapsSample

Sample code to demonstrate how to use the Maui.GoogleMaps plugin with .NET MAUI
C#
7
star
46

MauiMediaElementSample

Sample code to demonstrate how to get started with MediaElement in your .NET MAUI application
C#
7
star
47

MauiMopupsSample

Sample code to demonstrate how to work with Mopups in .NET MAUI
C#
7
star
48

XFDarkModeSample

C#
7
star
49

XCTPopupsSample

Sample code to demonstrate showing popups with Xamarin Community Toolkit in Xamarin.Forms apps
C#
7
star
50

XFMapsLiveTrackingSample

Sample code to demonstrate how to implement live tracking in Xamarin.Forms Maps
C#
7
star
51

ExistingSQLiteDbSample

Sample code to demonstrate how to work with an existing SQLite Database in Xamarin.Forms and .NET MAUI
C#
7
star
52

MauiToolkitSnackbarToastSample

Sample code to demonstrate how to work with Snackbar and Toast from the .NET MAUI Community Toolkit in your .NET MAUI app
C#
7
star
53

HideGoXLRWindow

This little solution hides the GoXLR App window on startup since there is no way to do that from the software itself
PowerShell
7
star
54

MauiDrawingViewSample

Sample code to demonstrate how to get started with the .NET MAUI Community Toolkit DrawingView
C#
7
star
55

AppCenterAnalyticsSample

Sample code to demonstrate how to add App Center Analytics to your Xamarin.Forms app
C#
7
star
56

MauiAndroidClearText

Sample code to demonstrate how to enable Android Cleartext Traffic in .NET MAUI
C#
6
star
57

DncMvvm

C#
6
star
58

MauiWindowsUnpackagesSample

Sample code to demonstrate how to build and distribute a so-called unpackaged Windows app with .NET MAUI
C#
6
star
59

MauiUnitTestSample

C#
6
star
60

MauiZXingBarcodeGeneratorSample

Sample code to demonstrate how to generate barcodes with ZXing and .NET MAUI
C#
6
star
61

MauiBlazorBindingsSample

Sample code to demonstrate how to get started with BlazorBindings.Maui in .NET MAUI
C#
6
star
62

XCTTabViewSample

Sample code that demonstrates the use of TabView in a Xamarin.Forms app
C#
6
star
63

MauiPluginAudioSample

Sample code to demonstrate how to work with Plugin.Maui.Audio in .NET MAUI
C#
6
star
64

MAUICustomHandlerSample

Sample code to demonstrate how to customize existing .NET MAUI controls with handlers
C#
6
star
65

MauiCustomizeControlSample

Sample code to demonstrate how to customize a control in .NET MAUI
C#
6
star
66

AzureCustomVisionDemo

Sample Xamarin.Forms app used on an episode of the AI Show
C#
6
star
67

CrossSimpleAudioPlayerSample

Sample repo for a question on StackOverflow about playing a sound in a Xamarin.Forms app
C#
6
star
68

MauiBottomSheetSample

Sample code to demonstrate how to add the The49.Maui.BottomSheet to your .NET MAUI app
C#
6
star
69

XFSQLiteCRUDSample

Sample code to demonstrate basic CRUD actions on SQLite with Xamarin.Forms and .NET MAUI
C#
6
star
70

XFEAccelerometerSample

Sample code on how to use the accelerometer and detect shaking with Xamarin.Essentials and Xamarin.Forms
C#
6
star
71

MauiBlazorAccessNativeSample

Sample code to demonstrate how to access device sensors from Blazor in .NET MAUI
C#
6
star
72

XFBiometricSample

Sample code which demonstrates how to authenticate with fingerprint/Touch ID or face recognition/Face ID in a Xamarin.Forms app
C#
6
star
73

MauiFilePickerSample

Sample code to demonstrate how to pick files in a .NET MAUI app
C#
5
star
74

XFOpenPDFSample

Sample code to demonstrate how to view PDFs in your Xamarin.Forms app
C#
5
star
75

XFXCalendarPluginSample

Sample code to demonstrate the Plugin.XCalendar plugin for Xamarin.Forms
C#
5
star
76

MauiBlazorDialogSample

Sample code to demonstrate how to show a platform-specific dialog from Blazor with .NET MAUI Blazor
C#
5
star
77

XCTSnackbarSample

Sample code to demonstrate how to use SnackBar and Toast with Xamarin.Forms apps and the Xamarin Community Toolkit
C#
5
star
78

XFLocalNotifications

Sample code to demonstrate how to implement local notifications with Xamarin.Forms
C#
5
star
79

MauiCameraMauiBarcodeScanningSample

Sample code to demonstrate how to do barcode scanning with the Camera.MAUI plugin in .NET MAUI
C#
5
star
80

MauiBlazorPlatformTabs

Sample code to demonstrate how to show different Blazor pages in platform tabs with .NET MAUI
CSS
5
star
81

XFEMediaPickerSample

Sample code for showing how to use Xamarin.Essentials MediaPicker
C#
5
star
82

StackNotifier

Get notified about your favorite tags on StackOverflow
JavaScript
5
star
83

HttpConditionalSample

Sample code for my blog post about using HTTP conditional requests
C#
5
star
84

MauiToolkitStatusBarBehaviorSample

Sample code to demonstrate how to change the status bar color in .NET MAUI using the .NET MAUI Community Toolkit
C#
5
star
85

GurCodesListviewGrouping

Code for my episode on how to implement grouping in a ListView
C#
5
star
86

MauiLottieAnimationsSample

Sample code to demonstrate how to add Lottie animations to your .NET MAUI app
C#
5
star
87

XFGenerateBarcodeSample

Sample code for generating barcodes in Xamarin.Forms and ZXing
C#
4
star
88

XFSwipeViewSample

Sample code to demonstrate the SwipeView in Xamarin.Forms
C#
4
star
89

XFSecureStorageSample

Sample code to demonstrate how to implement secure storage in your Xamarin.Forms and .NET MAUI app with Essentials
C#
4
star
90

CarouselViewSample

Sample code for the Xamarin.Forms CarouselView
C#
4
star
91

XFETextToSpeechSample

Sample code on how to implement text-to-speech with Xamarin.Essentials
C#
4
star
92

XFEOpenMapsSample

Sample code to demonstrate how to open the native maps app with Xamarin.Essentials
C#
4
star
93

MauiCSharpMarkupExample

Sample code to demonstrate the C# Markup Extensions for .NET MAUI (and Xamarin.Forms)
C#
4
star
94

MauiFreshMvvmSample

Sample code to demonstrate how to get started with FreshMvvm and .NET MAUI
C#
4
star
95

XFMAUIConvertBehaviorsSample

Sample code to demonstrate how to convert behaviors from Xamarin.Forms to .NET MAUI and how to use behaviors in .NET MAUI
C#
4
star
96

XFFreshMvvmIntroSample

Sample code to demonstrate how to start implementing FreshMvvm in your Xamarin.Forms app
C#
4
star
97

MauiGoogleVisionBarcodeScanningSample

Sample code to demonstrate how to use the Google Vision ML based barcode scanner in .NET MAUI
C#
4
star
98

MauiPlatformCodeSample

Sample code to demonstrate how to write code for a specific platform in .NET MAUI
C#
4
star
99

MauiToolkitFileSaverSample

Sample code to demonstrate the use of the .NET MAUI Community Toolkit FileSaver
C#
4
star
100

XFPlayBackgroundSample

Sample code to demonstrate how to play audio in the background and video Picture-in-Picture on iOS with MediaElement for Xamarin.Forms
C#
4
star