/
audioSession.ts
47 lines (44 loc) · 1.79 KB
/
audioSession.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { NativeModules } from 'react-native';
const AudioSessionModule = NativeModules.AudioSessionModule;
/**
* An audio session category defines a set of audio behaviors.
* Choose a category that most accurately describes the audio behavior you require.
*
* Note the `playback` category is required in order to properly enable picture in picture support.
*
* - `ambient`: The category for an app in which sound playback is nonprimary — that is, your app also works with the sound turned off.
* - `multiRoute`: The category for routing distinct streams of audio data to different output devices at the same time.
* - `playAndRecord`: The category for recording (input) and playback (output) of audio, such as for a Voice over Internet Protocol (VoIP) app.
* - `playback`: The category for playing recorded music or other sounds that are central to the successful use of your app.
* - `record`: The category for recording audio while also silencing playback audio.
* - `soloAmbient`: The default audio session category.
*
* @platform iOS
* @see https://developer.apple.com/documentation/avfaudio/avaudiosession/category
*/
export type AudioSessionCategory =
| 'ambient'
| 'multiRoute'
| 'playAndRecord'
| 'playback'
| 'record'
| 'soloAmbient';
/**
* An object that communicates to the system how you intend to use audio in your app.
*
* @platform iOS
* @see https://developer.apple.com/documentation/avfaudio/avaudiosession
*/
export const AudioSession = {
/**
* Sets the audio session's category.
*
* @platform iOS
* @see https://developer.apple.com/documentation/avfaudio/avaudiosession/1616583-setcategory
*/
setCategory: async (category: AudioSessionCategory): Promise<void> => {
if (AudioSessionModule) {
await AudioSessionModule.setCategory(category);
}
},
};