@umituz/react-native-sound 1.1.0 → 1.2.1

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/LICENSE CHANGED
@@ -20,3 +20,4 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
+
package/README.md CHANGED
@@ -280,3 +280,4 @@ MIT
280
280
 
281
281
  Ümit UZ <umit@umituz.com>
282
282
 
283
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-sound",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Universal sound playback and caching library for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -76,3 +76,4 @@ export interface SoundCacheInfo {
76
76
  cacheSize?: number;
77
77
  }
78
78
 
79
+
@@ -17,3 +17,4 @@ export interface IStorageService {
17
17
  getDownloadUrl(storagePath: string): Promise<string>;
18
18
  }
19
19
 
20
+
package/src/index.ts CHANGED
@@ -71,3 +71,4 @@ export {
71
71
 
72
72
  export type { UseSoundCacheResult } from './presentation/hooks/useSoundCache';
73
73
 
74
+
@@ -103,3 +103,4 @@ export class AudioPlaybackService {
103
103
  // Export singleton instance
104
104
  export const audioPlaybackService = new AudioPlaybackService();
105
105
 
106
+
@@ -144,3 +144,4 @@ export class SoundCacheService {
144
144
  // Export singleton instance
145
145
  export const soundCacheService = new SoundCacheService();
146
146
 
147
+
@@ -95,3 +95,4 @@ export class SoundSourceResolver {
95
95
  }
96
96
  }
97
97
 
98
+
File without changes
@@ -107,3 +107,4 @@ export function useSoundCache(): UseSoundCacheResult {
107
107
  };
108
108
  }
109
109
 
110
+
@@ -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 = async (
55
- sound: Sound,
56
- playbackOptions?: SoundPlaybackOptions,
57
- onDownloadProgress?: (progress: number) => void
58
- ) => {
59
- // Create resolver with storage service
60
- const resolver = new SoundSourceResolver(options.storageService);
61
-
62
- // Progress callback wrapper
63
- const progressCallback = onDownloadProgress
64
- ? (progress: number) => {
65
- useSoundPlaybackStore.setState({
66
- downloadingSoundId: sound.id,
67
- downloadProgress: Math.round(progress * 100),
68
- });
69
- onDownloadProgress(progress);
70
- }
71
- : undefined;
72
-
73
- // Resolve source
74
- const resolved = await resolver.resolve(sound, progressCallback);
75
- if (!resolved) {
76
- throw new Error(`Cannot resolve audio source for sound: ${sound.id}`);
77
- }
78
-
79
- // Pass resolved source to store via metadata
80
- const soundWithSource: Sound = {
81
- ...sound,
82
- metadata: {
83
- ...sound.metadata,
84
- _resolvedSource: resolved.source,
85
- _isStreaming: resolved.isStreaming,
86
- },
87
- };
88
-
89
- await store.playSound(soundWithSource, playbackOptions, onDownloadProgress);
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 */