forked from zmxv/react-native-sound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
202 lines (166 loc) · 6.43 KB
/
index.d.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Type definitions for react-native-sound
// Project: https://github.com/zmxv/react-native-sound
// Definitions by: Kyle Roach <https://github.com/iRoachie>
// TypeScript Version: 2.3.2
type AVAudioSessionCategory = 'Ambient' | 'SoloAmbient' | 'Playback' | 'Record' | 'PlayAndRecord' | 'AudioProcessing' | 'MultiRoute' | 'Alarm'
type AVAudioSessionMode = 'Default' | 'VoiceChat' | 'VideoChat' | 'GameChat' | 'VideoRecording' | 'Measurement' | 'MoviePlayback' | 'SpokenAudio'
type FilenameType = string
type FileType = any
type BasePathType = string
type CallbackType = (error: any) => void
declare class Sound {
static MAIN_BUNDLE: string
static DOCUMENT: string
static LIBRARY: string
static CACHES: string
/**
* Sets AVAudioSession as active, which is recommended on iOS to achieve seamless background playback.
* Use this method to deactivate the AVAudioSession when playback is finished in order for other apps
* to regain access to the audio stack.
*
* @param category AVAudioSession category
* @param mixWithOthers Can be set to true to force mixing with other audio sessions.
*/
static setActive(active: boolean): void
/**
* Sets AVAudioSession category, which allows playing sound in background,
* stop sound playback when phone is locked, etc.
* Parameter options: "Ambient", "SoloAmbient", "Playback", "Record", "PlayAndRecord", "AudioProcessing", "MultiRoute".
*
* @param category AVAudioSession category
* @param mixWithOthers Can be set to true to force mixing with other audio sessions.
*/
static setCategory(category: AVAudioSessionCategory, mixWithOthers?: boolean): void
/**
* Sets AVAudioSession mode, which works in conjunction with the category to determine audio mixing behavior.
* Parameter options: "Default", "VoiceChat", "VideoChat", "GameChat", "VideoRecording", "Measurement", "MoviePlayback", "SpokenAudio".
*
* @param mode AVAudioSession mode
* @param mixWithOthers Can be set to true to force mixing with other audio sessions.
*/
static setMode(mode: AVAudioSessionMode): void
/**
* @param filenameOrFile Either absolute or relative path to the sound file or the `require` call.
* @param basePathOrCallback Optional base path of the file. Omit this or pass '' if filename is an absolute path; you may use one of the predefined directories: Sound.MAIN_BUNDLE, Sound.DOCUMENT, Sound.LIBRARY, Sound.CACHES. If you are using `require` to define filepath, then set the callback function as the second argument.
* @param callback Optional callback function called when load ends in either success or error. In the event of success, error is undefined.
*/
constructor(filenameOrFile: FilenameType | FileType, basePathOrCallback?: BasePathType | CallbackType, callback?: CallbackType)
/**
* Return true if the sound has been loaded.
*/
isLoaded(): boolean
/**
* Plays the loaded file
* @param onEnd - Optional callback function that gets called when the playback finishes successfully or an audio decoding error interrupts it
*/
play(onEnd?: (success: boolean) => void): this
/**
* Pause the sound
* @param cb - Optional callback function that gets called when the sound has been paused.
*/
pause(cb?: () => void): this
/**
* Stop playback and set the seek position to 0.
* @param cb - Optional callback function that gets called when the sound has been stopped.
*/
stop(cb?: () => void): this
/**
* Reset the audio player to its uninitialized state (android only)
*/
reset(): this
/**
* Release the audio player resource associated with the instance.
*/
release(): this
/**
* Return the number of channels
* (1 for mono and 2 for stereo sound), or -1 before the sound gets loaded.
*/
getNumberOfChannels(): number
/**
* Return the time of audio (second)
*/
getDuration(): number
/**
* Return the volume of the audio player (not the system-wide volume),
* Ranges from 0.0 (silence) through 1.0 (full volume, the default)
*/
getVolume(): number
/**
* Set the volume
* @param value - ranging from 0.0 (silence) through 1.0 (full volume)
*/
setVolume(value: number): this
/**
* Return the stereo pan position of the audio player (not the system-wide pan)
* Ranges from -1.0 (full left) through 1.0 (full right). The default value is 0.0 (center)
*/
getPan(): number
/**
* Set the pan value
* @param value - ranging from -1.0 (full left) through 1.0 (full right).
*/
setPan(value: number): this
/**
* Return the loop count of the audio player.
* The default is 0 which means to play the sound once.
* On iOS a positive number specifies the number of times to return to the start and play again, a negative number indicates an indefinite loop.
* On Android any non-zero value indicates an indefinite loop.
*/
getNumberOfLoops(): number
/**
* Set the loop count
* @param value - iOS: 0 means to play the sound once, a positive number specifies the number of times to return to the start and play again, a negative number indicates an indefinite loop. Android: 0 means to play the sound once, other numbers indicate an indefinite loop.
*/
setNumberOfLoops(value: number): this
/**
* Callback will receive the current playback position in seconds and whether the sound is being played.
* @param cb
*/
getCurrentTime(cb?: (seconds: number, isPlaying: boolean) => void): void
/**
* Seek to a particular playback point in seconds.
* @param value
*/
setCurrentTime(value: number): this
/**
* Return the speed of the audio player
*/
getSpeed(): number
/**
* Speed of the audio playback (iOS Only).
* @param value
*/
setSpeed(value: number): this
/**
* Return the pitch of the audio player
*/
getPitch(): number
/**
* Pitch of the audio playback (Android Only).
* @param value
*/
setPitch(value: number): void
/**
* Whether to enable playback in silence mode (iOS only)
* @deprecated - Use the static method Sound.setCategory('Playback') instead which has the same effect.
* @param enabled
*/
enableInSilenceMode(enabled: boolean): void
/**
* Sets AVAudioSession category
* @deprecated
* @param value
*/
setCategory(value: AVAudioSessionCategory): void
/**
* Turn speaker phone on (android only)
* @param value
*/
setSpeakerphoneOn(value: boolean): void
/**
* Whether the player is playing or not.
*/
isPlaying(): boolean
}
export = Sound;