-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(audio-management): add plugin (#4894)
- Loading branch information
Showing
1 changed file
with
141 additions
and
0 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
src/@awesome-cordova-plugins/plugins/audio-management/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |