extension-avaudiosession

Adds support for setting AVAudioSession category
https://github.com/HaxeExtension/extension-avaudiosession

To install, run:

haxelib install extension-avaudiosession 1.0.0 

See using Haxelib in Haxelib documentation for more information.

README.md

extension-avaudiosession

An OpenFL extension that adds support for setting the audio session category on iOS.

This extension changes the default audio session category to AVAudioSessionCategoryAmbient. For more information about the different possible categories, see the official Audio Session Categories documentation.

Usage

Querying whether background audio is playing

A common use-case is to mute the game music while the user is listening to their own audio in the background (e.g. a podcast or music).

import extension.avaudiosession.AVAudioSession;
import openfl.display.Sprite;
import openfl.events.FocusEvent;

class AutoMuteBackgroundMusicExample extends Sprite
{
    public function new()
    {
        super();

        stage.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
    }

    function onFocusIn(e:FocusEvent)
    {
        if (AVAudioSession.backgroundAudio)
        {
            // Stop playing game music
        }
        else
        {
            // Start playing game music
        }
    }
}

Setting AVAudioSession category

If your app heavily relies on the audio, you might want to stop background audio from other sources playing while your app is focused.

import extension.avaudiosession.AVAudioSession;
import openfl.display.Sprite;

class MuteOtherBackgroundAudioExample extends Sprite
{
    public function new()
    {
        super();

        AVAudioSession.category = AVAudioSessionCategory.SoloAmbient;
    }
}

License

The MIT License (MIT) - LICENSE.md

Contributors
raggy
Version
1.0.0
Published
2 weeks ago
License
MIT

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github