expo-audio 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/audio/AudioPlayer.kt +5 -2
- package/android/src/main/java/expo/modules/audio/AudioRecorder.kt +9 -15
- package/android/src/main/java/expo/modules/audio/AudioRecords.kt +4 -4
- package/app.plugin.js +1 -0
- package/build/Audio.types.d.ts +10 -12
- package/build/Audio.types.d.ts.map +1 -1
- package/build/Audio.types.js.map +1 -1
- package/build/AudioModule.types.d.ts +8 -8
- package/build/AudioModule.types.d.ts.map +1 -1
- package/build/AudioModule.types.js.map +1 -1
- package/build/AudioModule.web.d.ts.map +1 -1
- package/build/AudioModule.web.js +4 -3
- package/build/AudioModule.web.js.map +1 -1
- package/build/ExpoAudio.d.ts +3 -0
- package/build/ExpoAudio.d.ts.map +1 -1
- package/build/ExpoAudio.js +7 -5
- package/build/ExpoAudio.js.map +1 -1
- package/build/ExpoAudio.web.d.ts.map +1 -1
- package/build/ExpoAudio.web.js +4 -3
- package/build/ExpoAudio.web.js.map +1 -1
- package/build/utils/options.js +6 -6
- package/build/utils/options.js.map +1 -1
- package/ios/AudioModule.swift +18 -15
- package/ios/AudioPlayer.swift +18 -14
- package/ios/AudioRecorder.swift +57 -11
- package/ios/AudioRecords.swift +2 -2
- package/ios/AudioUtils.swift +2 -2
- package/package.json +2 -2
- package/plugin/build/withAudio.d.ts +5 -0
- package/plugin/build/withAudio.js +17 -0
- package/plugin/src/withAudio.ts +26 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Audio.types.ts +10 -12
- package/src/AudioModule.types.ts +8 -8
- package/src/AudioModule.web.ts +4 -3
- package/src/ExpoAudio.ts +8 -6
- package/src/ExpoAudio.web.ts +4 -3
- package/src/utils/options.ts +6 -6
package/src/ExpoAudio.ts
CHANGED
|
@@ -15,22 +15,24 @@ import { AudioPlayer, AudioRecorder } from './AudioModule.types';
|
|
|
15
15
|
import { createRecordingOptions } from './utils/options';
|
|
16
16
|
import { resolveSource } from './utils/resolveSource';
|
|
17
17
|
|
|
18
|
+
export const PLAYBACK_STATUS_UPDATE = 'playbackStatusUpdate';
|
|
19
|
+
export const AUDIO_SAMPLE_UPDATE = 'audioSampleUpdate';
|
|
20
|
+
export const RECORDING_STATUS_UPDATE = 'recordingStatusUpdate';
|
|
21
|
+
|
|
18
22
|
export function useAudioPlayer(
|
|
19
23
|
source: AudioSource | string | number | null = null,
|
|
20
24
|
updateInterval: number = 500
|
|
21
25
|
): AudioPlayer {
|
|
22
26
|
const parsedSource = resolveSource(source);
|
|
23
|
-
|
|
27
|
+
return useReleasingSharedObject(
|
|
24
28
|
() => new AudioModule.AudioPlayer(parsedSource, updateInterval),
|
|
25
29
|
[JSON.stringify(parsedSource)]
|
|
26
30
|
);
|
|
27
|
-
|
|
28
|
-
return player;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export function useAudioPlayerStatus(player: AudioPlayer): AudioStatus {
|
|
32
34
|
const currentStatus = useMemo(() => player.currentStatus, [player.id]);
|
|
33
|
-
return useEvent(player,
|
|
35
|
+
return useEvent(player, PLAYBACK_STATUS_UPDATE, currentStatus);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
export function useAudioSampleListener(
|
|
@@ -42,7 +44,7 @@ export function useAudioSampleListener(
|
|
|
42
44
|
if (!player.isAudioSamplingSupported) {
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
|
-
const subscription = player.addListener(
|
|
47
|
+
const subscription = player.addListener(AUDIO_SAMPLE_UPDATE, listener);
|
|
46
48
|
return () => {
|
|
47
49
|
subscription.remove();
|
|
48
50
|
};
|
|
@@ -59,7 +61,7 @@ export function useAudioRecorder(
|
|
|
59
61
|
}, [JSON.stringify(platformOptions)]);
|
|
60
62
|
|
|
61
63
|
useEffect(() => {
|
|
62
|
-
const subscription = recorder.addListener(
|
|
64
|
+
const subscription = recorder.addListener(RECORDING_STATUS_UPDATE, (status) => {
|
|
63
65
|
statusListener?.(status);
|
|
64
66
|
});
|
|
65
67
|
return () => subscription.remove();
|
package/src/ExpoAudio.web.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from './Audio.types';
|
|
12
12
|
import { AudioPlayer, AudioRecorder } from './AudioModule.types';
|
|
13
13
|
import * as AudioModule from './AudioModule.web';
|
|
14
|
+
import { AUDIO_SAMPLE_UPDATE, PLAYBACK_STATUS_UPDATE, RECORDING_STATUS_UPDATE } from './ExpoAudio';
|
|
14
15
|
import { createRecordingOptions } from './utils/options';
|
|
15
16
|
import { resolveSource } from './utils/resolveSource';
|
|
16
17
|
|
|
@@ -33,7 +34,7 @@ export function useAudioPlayer(
|
|
|
33
34
|
|
|
34
35
|
export function useAudioPlayerStatus(player: AudioModule.AudioPlayerWeb): AudioStatus {
|
|
35
36
|
const currentStatus = useMemo(() => player.currentStatus, [player.id]);
|
|
36
|
-
return useEvent(player,
|
|
37
|
+
return useEvent(player, PLAYBACK_STATUS_UPDATE, currentStatus);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
export function useAudioSampleListener(
|
|
@@ -42,7 +43,7 @@ export function useAudioSampleListener(
|
|
|
42
43
|
) {
|
|
43
44
|
player.setAudioSamplingEnabled(true);
|
|
44
45
|
useEffect(() => {
|
|
45
|
-
const subscription = player.addListener(
|
|
46
|
+
const subscription = player.addListener(AUDIO_SAMPLE_UPDATE, listener);
|
|
46
47
|
return () => {
|
|
47
48
|
player.setAudioSamplingEnabled(false);
|
|
48
49
|
subscription.remove();
|
|
@@ -60,7 +61,7 @@ export function useAudioRecorder(
|
|
|
60
61
|
}, [JSON.stringify(platformOptions)]);
|
|
61
62
|
|
|
62
63
|
useEffect(() => {
|
|
63
|
-
const subscription = recorder.addListener(
|
|
64
|
+
const subscription = recorder.addListener(RECORDING_STATUS_UPDATE, (status) => {
|
|
64
65
|
statusListener?.(status);
|
|
65
66
|
});
|
|
66
67
|
return () => {
|
package/src/utils/options.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Platform } from 'expo-modules-core';
|
|
|
3
3
|
import { RecordingOptions } from '../Audio.types';
|
|
4
4
|
|
|
5
5
|
export function createRecordingOptions(options: RecordingOptions) {
|
|
6
|
-
let
|
|
6
|
+
let commonOptions = {
|
|
7
7
|
extension: options.extension,
|
|
8
8
|
sampleRate: options.sampleRate,
|
|
9
9
|
numberOfChannels: options.numberOfChannels,
|
|
@@ -11,15 +11,15 @@ export function createRecordingOptions(options: RecordingOptions) {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
if (Platform.OS === 'ios') {
|
|
14
|
-
|
|
15
|
-
...
|
|
14
|
+
commonOptions = {
|
|
15
|
+
...commonOptions,
|
|
16
16
|
...options.ios,
|
|
17
17
|
};
|
|
18
18
|
} else if (Platform.OS === 'android') {
|
|
19
|
-
|
|
20
|
-
...
|
|
19
|
+
commonOptions = {
|
|
20
|
+
...commonOptions,
|
|
21
21
|
...options.android,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return commonOptions;
|
|
25
25
|
}
|