Skip to content

SkylabsTechnology/capacitor-mixer

Repository files navigation

Mixer Plugin by Skylabs Technology

Android

Usage

Minimum target deployment: 28

to set this value you can add this to your ./android/variables.gradle

ext {
    minSdkVersion = 28
}

Permissions

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="@string/custom_url_scheme" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.OPEN_DOCUMENT" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="io.ionic.starter" />
    <data android:mimeType="audio/*" />
</intent-filter>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>

API

requestMixerPermissions()

requestMixerPermissions() => Promise<BaseResponse<null>>

Requests permissions required by the mixer plugin

  • iOS: Permissions must be added to application in the Info Target Properties

  • Android: Permissions must be added to AndroidManifest.XML

See README for additional information on permissions

Returns: Promise<BaseResponse<null>>


addListener(string, ...)

addListener(eventName: string, listenerFunc: (response: AudioSessionEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Adds listener for AudioSession events

Ex:

Register Listener:

Mixer.addListener("myEventName", this.myListenerFunction.bind(this));

myListenerFunction(response: <a href="#audiosessionevent">AudioSessionEvent</a>) { 
 // handle event 
}
Param Type
eventName string
listenerFunc (response: AudioSessionEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(string, ...)

addListener(eventName: string, listenerFunc: (response: MixerTimeEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Adds listener for audio track time update events

Ex:

Register Listener:

Mixer.addListener("myEventName", this.myListenerFunction.bind(this));

myListenerFunction(response: <a href="#mixertimeevent">MixerTimeEvent</a>) { 
 // handle event 
}
Param Type
eventName string
listenerFunc (response: MixerTimeResponse) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


addListener(string, ...)

addListener(eventName: string, listenerFunc: (response: VolumeMeterEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Adds listener for volume metering update events

Ex:

Register Listener:

Mixer.addListener("myEventName", this.myListenerFunction.bind(this));

myListenerFunction(response: <a href="#volumemeterevent">VolumeMeterEvent</a>) { 
 // handle event 
}
Param Type
eventName string
listenerFunc (response: VolumeMeterEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


playOrPause(...)

playOrPause(request: BaseMixerRequest) => Promise<BaseResponse<PlaybackStateResponse>>

Toggles playback and pause on an initialized audio file

Param Type
request BaseMixerRequest

Returns: Promise<BaseResponse<PlaybackStateResponse>>


stop(...)

stop(request: BaseMixerRequest) => Promise<BaseResponse<PlaybackStateResponse>>

Stops playback on a playing audio file

Param Type
request BaseMixerRequest

Returns: Promise<BaseResponse<PlaybackStateResponse>>


isPlaying(...)

isPlaying(request: BaseMixerRequest) => Promise<BaseResponse<IsPlayingResponse>>

A boolean that returns the playback state of initialized audio file

Param Type
request BaseMixerRequest

Returns: Promise<BaseResponse<IsPlayingResponse>>


getCurrentVolume(...)

getCurrentVolume(request: ChannelPropertyRequest) => Promise<BaseResponse<VolumeResponse>>

Returns current volume of a channel as a number between 0 and 1

Param Type
request ChannelPropertyRequest

Returns: Promise<BaseResponse<VolumeResponse>>


getCurrentEq(...)

getCurrentEq(request: ChannelPropertyRequest) => Promise<BaseResponse<EqResponse>>

Returns an object with numeric values for gain and frequency in bass, mid, and treble ranges

Param Type
request ChannelPropertyRequest

Returns: Promise<BaseResponse<EqResponse>>


initAudioFile(...)

initAudioFile(request: InitChannelRequest) => Promise<BaseResponse<InitResponse>>

Returns AudioId string of initialized audio file

Param Type
request InitChannelRequest

Returns: Promise<BaseResponse<InitResponse>>


adjustVolume(...)

adjustVolume(request: AdjustVolumeRequest) => Promise<BaseResponse<null>>

Adjusts volume for a channel

Param Type
request AdjustVolumeRequest

Returns: Promise<BaseResponse<null>>


adjustEq(...)

adjustEq(request: AdjustEqRequest) => Promise<BaseResponse<null>>

Adjusts gain and frequency in bass, mid, and treble ranges for a channel

Param Type
request AdjustEqRequest

Returns: Promise<BaseResponse<null>>


setElapsedTimeEvent(...)

setElapsedTimeEvent(request: SetEventRequest) => Promise<BaseResponse<null>>

Sets an elapsed time event name for a given audioId. To unset elapsedTimeEvent pass an empty string and this will stop the event from being triggered.

Only applicable for audio files

Param Type
request SetEventRequest

Returns: Promise<BaseResponse<null>>


getElapsedTime(...)

getElapsedTime(request: BaseMixerRequest) => Promise<BaseResponse<MixerTimeResponse>>

Returns an object representing hours, minutes, seconds, and milliseconds elapsed

Param Type
request BaseMixerRequest

Returns: Promise<BaseResponse<MixerTimeResponse>>


getTotalTime(...)

getTotalTime(request: BaseMixerRequest) => Promise<BaseResponse<MixerTimeResponse>>

Returns total time in an object of hours, minutes, seconds, and millisecond totals

Param Type
request BaseMixerRequest

Returns: Promise<BaseResponse<MixerTimeResponse>>


initMicInput(...)

initMicInput(request: InitChannelRequest) => Promise<BaseResponse<InitResponse>>

Initializes microphone channel on mixer

Returns AudioId string of initialized microphone input

Param Type
request InitChannelRequest

Returns: Promise<BaseResponse<InitResponse>>


getInputChannelCount()

getInputChannelCount() => Promise<BaseResponse<ChannelCountResponse>>

Returns the channel count and name of the initialized audio device

Returns: Promise<BaseResponse<ChannelCountResponse>>


initAudioSession(...)

initAudioSession(request: InitAudioSessionRequest) => Promise<BaseResponse<InitAudioSessionResponse>>

Initializes audio session with selected port type,

Returns a value describing the initialized port type for the audio session (usb, built-in, etc.)

Param Type
request InitAudioSessionRequest

Returns: Promise<BaseResponse<InitAudioSessionResponse>>


deinitAudioSession()

deinitAudioSession() => Promise<BaseResponse<null>>

Cancels audio session and resets selected port. Use prior to changing port type

Returns: Promise<BaseResponse<null>>


checkAudioSessionState()

checkAudioSessionState() => Promise<BaseResponse<SessionStateResponse>>

Checks the current state of the AudioSession.

Returns: Promise<BaseResponse<SessionStateResponse>>


resetPlugin()

resetPlugin() => Promise<BaseResponse<null>>

Resets plugin state back to its initial state

<span style="color: 'red'">CAUTION: This will completely wipe everything you have initialized from the plugin!</span>

Returns: Promise<BaseResponse<null>>


getAudioSessionPreferredInputPortType()

getAudioSessionPreferredInputPortType() => Promise<BaseResponse<InitResponse>>

Returns a value describing the initialized port type for the audio session (usb, built-in, etc.)

Returns: Promise<BaseResponse<InitResponse>>


destroyMicInput(...)

destroyMicInput(request: BaseMixerRequest) => Promise<BaseResponse<DestroyResponse>>

De-initializes a mic input channel based on audioId

Note: Once destroyed, the channel cannot be recovered

Param Type Description
request BaseMixerRequest audioId

Returns: Promise<BaseResponse<DestroyResponse>>


destroyAudioFile(...)

destroyAudioFile(request: BaseMixerRequest) => Promise<BaseResponse<DestroyResponse>>

De-initializes an audio file channel based on audioId

Note: Once destroyed, the channel cannot be recovered

Param Type Description
request BaseMixerRequest audioId

Returns: Promise<BaseResponse<DestroyResponse>>


validateFileUri(...)

validateFileUri(request: FileValidationRequest) => Promise<BaseResponse<FileValidationResponse>>

Validates file path and returns true if valid, false if invalid

Param Type
request FileValidationRequest

Returns: Promise<BaseResponse<FileValidationResponse>>


startStream(...)

startStream(request: StreamRequest) => Promise<BaseResponse<null>>

Starts a stream to a provided URL

Param Type
request StreamRequest

Returns: Promise<BaseResponse<null>>


stopStream()

stopStream() => Promise<BaseResponse<null>>

Stops a stream if one is currently active.

Returns: Promise<BaseResponse<null>>


Interfaces

BaseResponse

The response wrapper for all response objects

Prop Type Description
status ResponseStatus Status of returned request. Ex: 'SUCCESS', 'ERROR'
message string Message that describes response Note: Can be used for user messages
data T Response data object field Ex: A MixerTimeResponse object

PluginListenerHandle

Prop Type
remove () => Promise<void>

AudioSessionEvent

Event response for handling audio session notifications

Prop Type Description
handlerType AudioSessionHandlerTypes The event type that occurred

MixerTimeResponse

Response representing HH:MM:SS.ms-formatted time

Prop Type Description
milliSeconds number ms in formatted time
seconds number SS in formatted time
minutes number MM in formatted time
hours number HH in formatted time

VolumeMeterEvent

Event response for handling current volume level

Prop Type Description
meterLevel number Calculated amplitude in dB - Range: -80 to 0 dB

PlaybackStateResponse

Response that returns PlayerState

Prop Type Description
state PlayerState Represents the state of the player

BaseMixerRequest

Base class for all mixer requests, consists of audioId only

Prop Type Description
audioId string A string identifying the audio file or microphone channel instance

IsPlayingResponse

Response for tracking player state as a boolean

Prop Type Description
value boolean Value of tracked player state

VolumeResponse

Response for tracking channel volume

Prop Type Description
volume number Value of tracked channel volume

ChannelPropertyRequest

Request to get info about channel properties such as current volume, EQ, etc.

Prop Type Description
inputType InputType Type of input on which properties are being requested

EqResponse

Response for tracking channel EQ

Prop Type Description
bassGain number Bass gain for channel - Range: -36 to +15 dB
bassFrequency number Bass frequency for channel - Suggested range: 20Hz to 499Hz
midGain number Mid gain for channel - Range: -36 to +15 dB
midFrequency number Mid frequency for channel - Suggested range: 500Hz to 1499Hz
trebleGain number Treble gain for channel - Range: -36 to +15 dB
trebleFrequency number Treble frequency for channel - Suggested range: 1.5kHz to 20kHz

InitResponse

Response for initialization of channel

Prop Type Description
value string Initialized channel audioId

InitChannelRequest

Request used to initialize a channel on the mixer

Prop Type Description
filePath string A string identifying the path to the audio file on device. Unused if initializing microphone channel
elapsedTimeEventName string A string identifying the elapsed time event name. This will automatically set the event and setElapsedTimeEvent is not needed. Unused if initializing microphone channel
channelNumber number The channel number being initialized for microphone. Starts at 0. Unused if initializing audio file
bassGain number Optional bass gain setting for initialization: -36dB to +15 dB Default: 0dB
bassFrequency number Optional init eq setting for bass EQ band iOS Default: 115Hz Android Default: 200Hz
midGain number Optional mid gain setting for initialization: -36dB to +15 dB Default: 0dB
midFrequency number Optional init setting for mid EQ band iOS Default: 500Hz Android Default: 1499Hz
trebleGain number Optional treble gain setting for initialization: -36dB to +15 dB Default: 0dB
trebleFrequency number Optional init eq setting for treble EQ band iOS Default: 1.5kHz Android Default: 20kHz
volume number Optional init setting for volume Default: 1 Range: 0 - 1
channelListenerName string Required name used to set listener for volume metering Subscribed event returns VolumeMeterEvent Note: if empty string is passed, metering will be disabled on channel

AdjustVolumeRequest

For mixer requests manipulating volume level

Prop Type Description
volume number A number between 0 and 1 specifying volume level being set
inputType InputType Type of input on which volume is being adjusted

AdjustEqRequest

For mixer requests manipulating EQ

Prop Type Description
eqType EqType Identifies EQ band to adjust: Bass, Mid, Treble
gain number A number between -36dB and +15dB identifying EQ band gain
frequency number A number identifying cutoff/central frequency for EQ band Bass: - iOS implemented as a low shelf - Android implemented as a high pass filter Mid: - implemented as a parametric 'bump' Treble: - iOS implemented as a high shelf - Android implemented as a low pass filter
inputType InputType Type of input on which EQ is being adjusted

SetEventRequest

Request to set an event listener

Prop Type Description
eventName string The name of the event that will be subscribed to Subscribed event returns MixerTimeEvent

ChannelCountResponse

Response for channel count of requested audio port

Prop Type Description
channelCount number Number of channels found
deviceName string Name of the device at the requested audio port

InitAudioSessionResponse

Response for initalizing audio session

Prop Type Description
preferredInputPortType AudioSessionPortType Type found when initializing audio session
preferredInputPortName string Device name found when initializing audio session
preferredIOBufferDuration number iOS only Preferred buffer duration when initializing audio session

InitAudioSessionRequest

Request to initialize an audio session

Prop Type Description
inputPortType AudioSessionPortType An enum describing input hardware device to be used
ioBufferDuration number iOS only The preferred duration of the input buffer (0.05 recommended as a starting point, change may be observed as output latency)
audioSessionListenerName string The name of the audio session event that will be subscribed to. Subscribed event returns AudioSessionEvent

SessionStateResponse

Response that returns PlayerState

Prop Type Description
state boolean Represents the state of the player

DestroyResponse

Response for destroying a channel

Prop Type Description
listenerName string The name of the volume metering event Note: If no event is found, empty string is returned
elapsedTimeEventName string The name of the elapsed time event Note: If no event is found, empty string is returned

FileValidationResponse

Response for validating file path

Prop Type Description
isFileValid boolean True if file path is found, False if file path is not found
filePath string File path that was checked.

FileValidationRequest

Request to validate a file path.

Prop Type Description
filePath string The file path that will be validated.

StreamRequest

Request to stream audio to provided url

Prop Type
streamUrl string

Type Aliases

MixerTimeEvent

Event response for handling current elapsed time

MixerTimeResponse

PlayerState

Possible states of player

"play" | "pause" | "stop" | "not implemented"

Enums

ResponseStatus

Members Value
SUCCESS "success"
ERROR "error"

AudioSessionHandlerTypes

Members Value Description
INTERRUPT_BEGAN "INTERRUPT_BEGAN" Invoked when another audio session has started This can cause your audio to be 'ducked', or silenced with the audio session
INTERRUPT_ENDED "INTERRUPT_ENDED" Invoked when another audio session has ended Your audio session should resume
ROUTE_DEVICE_DISCONNECTED "ROUTE_DEVICE_DISCONNECTED" Invoked when the device you're currently connected to is disconnected from the audio session
ROUTE_DEVICE_RECONNECTED "ROUTE_DEVICE_RECONNECTED" Invoked when previously-used device is reconnected to the audio session
ROUTE_NEW_DEVICE_FOUND "ROUTE_NEW_DEVICE_FOUND" Invoked when previously-UNUSED device is connected to the audio session

InputType

Members Value
MIC "mic"
FILE "file"

EqType

Members Value
BASS "bass"
MID "mid"
TREBLE "treble"

AudioSessionPortType

Members Value Description
HDMI "hdmi"
AIRPLAY "airplay" iOS only
BLUETOOTH_A2DP "bluetoothA2DP"
BLUETOOTH_HFP "bluetoothHFP"
BLUETOOTH_LE "bluetoothLE" iOS only
BUILT_IN_MIC "builtInMic"
HEADSET_MIC_WIRED "headsetMicWired" iOS only
HEADSET_MIC_USB "headsetMicUsb"
LINE_IN "lineIn"
THUNDERBOLT "thunderbolt" iOS only
USB_AUDIO "usbAudio"
VIRTUAL "virtual"

About

Mixer implementation for Ionic Capacitor

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published