Coder Social home page Coder Social logo

sirjohnk / plugin.maui.audio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jfversluis/plugin.maui.audio

1.0 0.0 0.0 12.73 MB

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

License: MIT License

C# 100.00%

plugin.maui.audio's Introduction

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.

plugin.maui.audio's People

Contributors

jfversluis avatar bijington avatar marcmognol avatar sirjohnk avatar ewerspej avatar matthewclendening avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.