@umituz/react-native-sound 1.2.3 → 1.2.5
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/package.json +1 -1
- package/src/AudioManager.ts +13 -6
package/package.json
CHANGED
package/src/AudioManager.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Audio, AVPlaybackStatus, AVPlaybackStatusSuccess } from 'expo-av';
|
|
1
|
+
import { Audio, AVPlaybackStatus, AVPlaybackStatusSuccess, InterruptionModeIOS, InterruptionModeAndroid } from 'expo-av';
|
|
2
2
|
import { useSoundStore } from './store';
|
|
3
3
|
import { PlaybackOptions, SoundSource } from './types';
|
|
4
4
|
|
|
@@ -14,12 +14,14 @@ class AudioManager {
|
|
|
14
14
|
try {
|
|
15
15
|
await Audio.setAudioModeAsync({
|
|
16
16
|
playsInSilentModeIOS: true,
|
|
17
|
-
staysActiveInBackground:
|
|
17
|
+
staysActiveInBackground: false,
|
|
18
18
|
shouldDuckAndroid: true,
|
|
19
19
|
playThroughEarpieceAndroid: false,
|
|
20
|
+
interruptionModeIOS: InterruptionModeIOS.DuckOthers,
|
|
21
|
+
interruptionModeAndroid: InterruptionModeAndroid.DuckOthers,
|
|
20
22
|
});
|
|
21
23
|
} catch (error) {
|
|
22
|
-
console.warn('Failed to configure audio session', error);
|
|
24
|
+
if (__DEV__) console.warn('Failed to configure audio session', error);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -48,16 +50,16 @@ class AudioManager {
|
|
|
48
50
|
async play(id: string, source: SoundSource, options?: PlaybackOptions) {
|
|
49
51
|
const store = useSoundStore.getState();
|
|
50
52
|
|
|
53
|
+
if (__DEV__) console.log('[AudioManager] Play called with ID:', id);
|
|
54
|
+
|
|
51
55
|
// If same ID is playing/pausing
|
|
52
56
|
if (this.currentId === id && this.sound) {
|
|
53
57
|
const status = await this.sound.getStatusAsync();
|
|
54
58
|
if (status.isLoaded) {
|
|
55
59
|
if (status.isPlaying) {
|
|
56
|
-
// If already playing, maybe they want to restart? Or just return?
|
|
57
|
-
// User wanted "toggle" behavior usually in the app, but the manager should be explicit.
|
|
58
|
-
// Let's assume play() means resume or restart.
|
|
59
60
|
return;
|
|
60
61
|
} else {
|
|
62
|
+
if (__DEV__) console.log('[AudioManager] Resuming existing sound');
|
|
61
63
|
await this.sound.playAsync();
|
|
62
64
|
return;
|
|
63
65
|
}
|
|
@@ -72,6 +74,8 @@ class AudioManager {
|
|
|
72
74
|
store.setCurrent(id, source);
|
|
73
75
|
store.setError(null);
|
|
74
76
|
|
|
77
|
+
if (__DEV__) console.log('[AudioManager] Creating sound from source:', source);
|
|
78
|
+
|
|
75
79
|
const { sound } = await Audio.Sound.createAsync(
|
|
76
80
|
source as any,
|
|
77
81
|
{
|
|
@@ -85,9 +89,12 @@ class AudioManager {
|
|
|
85
89
|
);
|
|
86
90
|
|
|
87
91
|
this.sound = sound;
|
|
92
|
+
if (__DEV__) console.log('[AudioManager] Sound created and playing');
|
|
88
93
|
} catch (error: any) {
|
|
94
|
+
if (__DEV__) console.error('[AudioManager] Error playing sound:', error);
|
|
89
95
|
store.setError(error.message);
|
|
90
96
|
this.currentId = null;
|
|
97
|
+
throw error;
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
100
|
|