1import ExponentAV from '../ExponentAV';
2
3let _enabled = true;
4
5export function isAudioEnabled(): boolean {
6  return _enabled;
7}
8
9export function throwIfAudioIsDisabled(): void {
10  if (!_enabled) {
11    throw new Error('Cannot complete operation because audio is not enabled.');
12  }
13}
14
15// @needsAudit
16/**
17 * Audio is enabled by default, but if you want to write your own Audio API in a bare workflow app, you might want to disable the Audio API.
18 * @param value `true` enables Audio, and `false` disables it.
19 * @return A `Promise` that will reject if audio playback could not be enabled for the device.
20 */
21export async function setIsEnabledAsync(value: boolean): Promise<void> {
22  _enabled = value;
23  await ExponentAV.setAudioIsEnabled(value);
24  // TODO : We immediately pause all players when disabled, but we do not resume all shouldPlay
25  // players when enabled. Perhaps for completeness we should allow this; the design of the
26  // enabling API is for people to enable / disable this audio library, but I think that it should
27  // intuitively also double as a global pause/resume.
28}
29