@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-sound",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
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",
@@ -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 */