|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Cordova, AwesomeCordovaNativePlugin, Plugin } from '@awesome-cordova-plugins/core'; |
| 3 | + |
| 4 | +/** |
| 5 | + * @name Audio Management |
| 6 | + * @description |
| 7 | + * A Cordova plugin to manage volume of audio streams for: ring, music, notification and system. Possible |
| 8 | + * ringer values for those streams are: silent, vibrate and normal. |
| 9 | + * |
| 10 | + * @usage |
| 11 | + * ```typescript |
| 12 | + * constructor(public audioman: AudioManagement) { } |
| 13 | + * |
| 14 | + * ... |
| 15 | + * |
| 16 | + * setAudioMode() { |
| 17 | + * this.audioman.setAudioMode(AudioManagement.AudioMode.NORMAL) |
| 18 | + * .then(() => { |
| 19 | + * console.log('Device audio mode is now NORMAL'); |
| 20 | + * }) |
| 21 | + * .catch((reason) => { |
| 22 | + * console.log(reason); |
| 23 | + * }); |
| 24 | + * } |
| 25 | + * |
| 26 | + * getAudioMode() { |
| 27 | + * this.audioman.getAudioMode() |
| 28 | + * .then((value: AudioManagement.AudioModeReturn) => { |
| 29 | + * console.log('Device audio mode is ' + value.label + ' (' + value.audioMode + ')'); |
| 30 | + * }) |
| 31 | + * .catch((reason) => { |
| 32 | + * console.log(reason); |
| 33 | + * }); |
| 34 | + * } |
| 35 | + * |
| 36 | + * ``` |
| 37 | + * @interfaces |
| 38 | + * AudioMode |
| 39 | + * AudioModeReturn |
| 40 | + * VolumeType |
| 41 | + */ |
| 42 | +@Plugin({ |
| 43 | + pluginName: 'AudioManagement', |
| 44 | + plugin: 'clovelced-plugin-audiomanagement', |
| 45 | + pluginRef: 'AudioManagement', |
| 46 | + repo: 'https://github.com/clovelCed/cordova-plugin-audiomanagement', |
| 47 | + platforms: ['Android'] |
| 48 | +}) |
| 49 | +@Injectable() |
| 50 | +export class Appsflyer extends AwesomeCordovaNativePlugin { |
| 51 | + /** |
| 52 | + * Sets the `AudioManagement.AudioMode` for the device. |
| 53 | + * |
| 54 | + * @param {AudioManagement.AudioMode} mode the device can be set to: Silent, Normal, Vibrate |
| 55 | + * @returns {Promise<void>} |
| 56 | + */ |
| 57 | + @Cordova({ |
| 58 | + successIndex: 1, |
| 59 | + errorIndex: 2 |
| 60 | + }) |
| 61 | + setAudioMode(mode: AudioManagement.AudioMode): Promise<void> { |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Gets the current `AudioManagement.AudioMode` of the device. Thenable returns an object with |
| 67 | + * `label` and `audioMode` values. |
| 68 | + * |
| 69 | + * @returns {Promise<AudioManagement.AudioModeReturn>} |
| 70 | + */ |
| 71 | + @Cordova() |
| 72 | + getAudioMode(): Promise<AudioManagement.AudioModeReturn> { |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Sets the specified `AudioManagement.VolumeType` for the device with the value from `volume`. |
| 78 | + * |
| 79 | + * @param {AudioManagement.VolumeType} type the `AudioManagement.VolumeType` to set |
| 80 | + * @param {number} volume the volume value |
| 81 | + * @returns {Promise<void>} |
| 82 | + */ |
| 83 | + @Cordova({ |
| 84 | + successIndex: 2, |
| 85 | + errorIndex: 3 |
| 86 | + }) |
| 87 | + setVolume(type: AudioManagement.VolumeType, volume: number): Promise<void> { |
| 88 | + return; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Gets the specified `AudioManagement.VolumeType`'s `volume`. Thenable returns an object with |
| 93 | + * a numeric property for volume, `volume`. |
| 94 | + * |
| 95 | + * @param {AudioManagement.VolumeType} type the `AudioManagement.VolumeType` to get |
| 96 | + * @returns {Promise<{volume: number}>} |
| 97 | + */ |
| 98 | + @Cordova({ |
| 99 | + successIndex: 1, |
| 100 | + errorIndex: 2 |
| 101 | + }) |
| 102 | + getVolume(type: AudioManagement.VolumeType): Promise<{ volume: number }> { |
| 103 | + return; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Gets the specified `AudioManagement.VolumeType`'s maximum `volume`. Thenable returns an |
| 108 | + * object with a numeric property, `maxVolume`. |
| 109 | + * |
| 110 | + * @param {AudioManagement.VolumeType} type the `AudioManagement.VolumeType` to get |
| 111 | + * @returns {Promise<{maxVolume: number}>} |
| 112 | + */ |
| 113 | + @Cordova({ |
| 114 | + successIndex: 1, |
| 115 | + errorIndex: 2 |
| 116 | + }) |
| 117 | + getMaxVolume(type: AudioManagement.VolumeType): Promise<{ maxVolume: number }> { |
| 118 | + return; |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | + |
| 123 | +export namespace AudioManagement { |
| 124 | + export enum AudioMode { |
| 125 | + SILENT = 0, |
| 126 | + VIBRATE, |
| 127 | + NORMAL |
| 128 | + } |
| 129 | + |
| 130 | + export enum VolumeType { |
| 131 | + RING = 0, |
| 132 | + MUSIC, |
| 133 | + NOTIFICATION, |
| 134 | + SYSTEM |
| 135 | + } |
| 136 | + |
| 137 | + export interface AudioModeReturn { |
| 138 | + audioMode: AudioManagement.AudioMode; |
| 139 | + label: string; |
| 140 | + } |
| 141 | +} |
0 commit comments