@umituz/react-native-sound 1.1.0 → 1.2.0
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
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* KISS: Simple hook wrapper around store
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { useEffect } from 'react';
|
|
10
|
+
import { useEffect, useCallback } from 'react';
|
|
11
11
|
import { useSoundPlaybackStore } from '../../infrastructure/storage/SoundPlaybackStore';
|
|
12
12
|
import { audioPlaybackService } from '../../infrastructure/services/AudioPlaybackService';
|
|
13
13
|
import type { Sound, SoundPlaybackOptions } from '../../domain/entities/Sound.entity';
|
|
@@ -51,43 +51,46 @@ export function useSoundPlayback(options: UseSoundPlaybackOptions = {}) {
|
|
|
51
51
|
/**
|
|
52
52
|
* Play a sound
|
|
53
53
|
*/
|
|
54
|
-
const playSound =
|
|
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
|
-
|
|
54
|
+
const playSound = useCallback(
|
|
55
|
+
async (
|
|
56
|
+
sound: Sound,
|
|
57
|
+
playbackOptions?: SoundPlaybackOptions,
|
|
58
|
+
onDownloadProgress?: (progress: number) => void
|
|
59
|
+
) => {
|
|
60
|
+
// Create resolver with storage service
|
|
61
|
+
const resolver = new SoundSourceResolver(options.storageService);
|
|
62
|
+
|
|
63
|
+
// Progress callback wrapper
|
|
64
|
+
const progressCallback = onDownloadProgress
|
|
65
|
+
? (progress: number) => {
|
|
66
|
+
useSoundPlaybackStore.setState({
|
|
67
|
+
downloadingSoundId: sound.id,
|
|
68
|
+
downloadProgress: Math.round(progress * 100),
|
|
69
|
+
});
|
|
70
|
+
onDownloadProgress(progress);
|
|
71
|
+
}
|
|
72
|
+
: undefined;
|
|
73
|
+
|
|
74
|
+
// Resolve source
|
|
75
|
+
const resolved = await resolver.resolve(sound, progressCallback);
|
|
76
|
+
if (!resolved) {
|
|
77
|
+
throw new Error(`Cannot resolve audio source for sound: ${sound.id}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Pass resolved source to store via metadata
|
|
81
|
+
const soundWithSource: Sound = {
|
|
82
|
+
...sound,
|
|
83
|
+
metadata: {
|
|
84
|
+
...sound.metadata,
|
|
85
|
+
_resolvedSource: resolved.source,
|
|
86
|
+
_isStreaming: resolved.isStreaming,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
await store.playSound(soundWithSource, playbackOptions, onDownloadProgress);
|
|
91
|
+
},
|
|
92
|
+
[options.storageService, store]
|
|
93
|
+
);
|
|
91
94
|
|
|
92
95
|
return {
|
|
93
96
|
/** Play a sound */
|