Skip to content

Commit

Permalink
feat(audio-management): add plugin (#4894)
Browse files Browse the repository at this point in the history
  • Loading branch information
blavenie authored Jan 6, 2025
1 parent 54d5eea commit 2a3b1b3
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/@awesome-cordova-plugins/plugins/audio-management/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { Injectable } from '@angular/core';
import { Cordova, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core';

/**
* @name Audio Management
* @description
* A Cordova plugin to manage volume of audio streams for: ring, music, notification and system. Possible
* ringer values for those streams are: silent, vibrate and normal.
*
* @usage
* ```typescript
* constructor(public audioman: AudioManagement) { }
*
* ...
*
* setAudioMode() {
* this.audioman.setAudioMode(AudioManagement.AudioMode.NORMAL)
* .then(() => {
* console.log('Device audio mode is now NORMAL');
* })
* .catch((reason) => {
* console.log(reason);
* });
* }
*
* getAudioMode() {
* this.audioman.getAudioMode()
* .then((value: AudioManagement.AudioModeReturn) => {
* console.log('Device audio mode is ' + value.label + ' (' + value.audioMode + ')');
* })
* .catch((reason) => {
* console.log(reason);
* });
* }
*
* ```
* @interfaces
* AudioMode
* AudioModeReturn
* VolumeType
*/
@Plugin({
pluginName: 'AudioManagement',
plugin: 'clovelced-plugin-audiomanagement',
pluginRef: 'AudioManagement',
repo: 'https://github.com/clovelCed/cordova-plugin-audiomanagement',
platforms: ['Android']
})
@Injectable()
export class Appsflyer extends AwesomeCordovaNativePlugin {
/**
* Sets the `AudioManagement.AudioMode` for the device.
*
* @param {AudioManagement.AudioMode} mode the device can be set to: Silent, Normal, Vibrate
* @returns {Promise<void>}
*/
@Cordova({
successIndex: 1,
errorIndex: 2
})
setAudioMode(mode: AudioManagement.AudioMode): Promise<void> {
return;
}

/**
* Gets the current `AudioManagement.AudioMode` of the device. Thenable returns an object with
* `label` and `audioMode` values.
*
* @returns {Promise<AudioManagement.AudioModeReturn>}
*/
@Cordova()
getAudioMode(): Promise<AudioManagement.AudioModeReturn> {
return;
}

/**
* Sets the specified `AudioManagement.VolumeType` for the device with the value from `volume`.
*
* @param {AudioManagement.VolumeType} type the `AudioManagement.VolumeType` to set
* @param {number} volume the volume value
* @returns {Promise<void>}
*/
@Cordova({
successIndex: 2,
errorIndex: 3
})
setVolume(type: AudioManagement.VolumeType, volume: number): Promise<void> {
return;
}

/**
* Gets the specified `AudioManagement.VolumeType`'s `volume`. Thenable returns an object with
* a numeric property for volume, `volume`.
*
* @param {AudioManagement.VolumeType} type the `AudioManagement.VolumeType` to get
* @returns {Promise<{volume: number}>}
*/
@Cordova({
successIndex: 1,
errorIndex: 2
})
getVolume(type: AudioManagement.VolumeType): Promise<{ volume: number }> {
return;
}

/**
* Gets the specified `AudioManagement.VolumeType`'s maximum `volume`. Thenable returns an
* object with a numeric property, `maxVolume`.
*
* @param {AudioManagement.VolumeType} type the `AudioManagement.VolumeType` to get
* @returns {Promise<{maxVolume: number}>}
*/
@Cordova({
successIndex: 1,
errorIndex: 2
})
getMaxVolume(type: AudioManagement.VolumeType): Promise<{ maxVolume: number }> {
return;
}
}


export namespace AudioManagement {
export enum AudioMode {
SILENT = 0,
VIBRATE,
NORMAL
}

export enum VolumeType {
RING = 0,
MUSIC,
NOTIFICATION,
SYSTEM
}

export interface AudioModeReturn {
audioMode: AudioManagement.AudioMode;
label: string;
}
}

0 comments on commit 2a3b1b3

Please sign in to comment.