@umituz/react-native-sound 1.2.7 β†’ 1.2.9

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.
Files changed (4) hide show
  1. package/package.json +3 -1
  2. package/src/store.ts +21 -23
  3. package/LICENSE +0 -23
  4. package/README.md +0 -283
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-sound",
3
- "version": "1.2.7",
3
+ "version": "1.2.9",
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",
@@ -26,11 +26,13 @@
26
26
  "url": "https://github.com/umituz/react-native-sound"
27
27
  },
28
28
  "peerDependencies": {
29
+ "@umituz/react-native-storage": "latest",
29
30
  "expo-av": ">=15.0.0",
30
31
  "react": ">=18.2.0",
31
32
  "react-native": ">=0.74.0"
32
33
  },
33
34
  "devDependencies": {
35
+ "@umituz/react-native-storage": "latest",
34
36
  "expo-av": "~13.4.1",
35
37
  "@types/react": "~19.1.10",
36
38
  "react": "19.1.0",
package/src/store.ts CHANGED
@@ -1,17 +1,17 @@
1
- import { create } from 'zustand';
2
- import { SoundState } from './types';
1
+ import { createStore } from '@umituz/react-native-storage';
2
+ import type { SoundState, SoundSource } from './types';
3
3
 
4
- interface SoundStore extends SoundState {
4
+ interface SoundActions {
5
5
  setPlaying: (isPlaying: boolean) => void;
6
6
  setBuffering: (isBuffering: boolean) => void;
7
7
  setProgress: (position: number, duration: number) => void;
8
8
  setError: (error: string | null) => void;
9
- setCurrent: (id: string | null, source: any) => void;
9
+ setCurrent: (id: string | null, source: SoundSource | null) => void;
10
10
  setVolumeState: (volume: number) => void;
11
11
  reset: () => void;
12
12
  }
13
13
 
14
- export const useSoundStore = create<SoundStore>((set) => ({
14
+ const initialSoundState: SoundState = {
15
15
  isPlaying: false,
16
16
  isBuffering: false,
17
17
  positionMillis: 0,
@@ -21,22 +21,20 @@ export const useSoundStore = create<SoundStore>((set) => ({
21
21
  error: null,
22
22
  currentSource: null,
23
23
  currentId: null,
24
+ };
24
25
 
25
- setPlaying: (isPlaying) => set({ isPlaying }),
26
- setBuffering: (isBuffering) => set({ isBuffering }),
27
- setProgress: (position, duration) =>
28
- set({ positionMillis: position, durationMillis: duration }),
29
- setError: (error) => set({ error }),
30
- setCurrent: (id, source) => set({ currentId: id, currentSource: source }),
31
- setVolumeState: (volume) => set({ volume }),
32
- reset: () =>
33
- set({
34
- isPlaying: false,
35
- isBuffering: false,
36
- positionMillis: 0,
37
- durationMillis: 0,
38
- error: null,
39
- currentSource: null,
40
- currentId: null,
41
- }),
42
- }));
26
+ export const useSoundStore = createStore<SoundState, SoundActions>({
27
+ name: 'sound-store',
28
+ initialState: initialSoundState,
29
+ persist: false,
30
+ actions: (set) => ({
31
+ setPlaying: (isPlaying) => set({ isPlaying }),
32
+ setBuffering: (isBuffering) => set({ isBuffering }),
33
+ setProgress: (position, duration) =>
34
+ set({ positionMillis: position, durationMillis: duration }),
35
+ setError: (error) => set({ error }),
36
+ setCurrent: (id, source) => set({ currentId: id, currentSource: source }),
37
+ setVolumeState: (volume) => set({ volume }),
38
+ reset: () => set(initialSoundState),
39
+ }),
40
+ });
package/LICENSE DELETED
@@ -1,23 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Ümit UZ
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
23
-
package/README.md DELETED
@@ -1,283 +0,0 @@
1
- # @umituz/react-native-sound
2
-
3
- Universal sound playback and caching library for React Native apps. Supports local assets, remote URLs, and automatic caching with a simple, clean API.
4
-
5
- ## Features
6
-
7
- - 🎡 **Universal Sound Playback** - Play sounds from local assets or remote URLs
8
- - πŸ’Ύ **Automatic Caching** - Cache remote sounds locally for offline playback
9
- - πŸ”„ **Streaming Support** - Stream sounds while downloading in background
10
- - πŸŽ›οΈ **Playback Controls** - Play, pause, stop, volume, and rate control
11
- - 🎯 **Singleton Pattern** - Only one sound plays at a time across the app
12
- - πŸ”Œ **Storage Abstraction** - Works with any storage provider (Firebase, AWS S3, etc.)
13
- - πŸ“¦ **Zero Dependencies** - Only requires `expo-av` and `expo-file-system`
14
-
15
- ## Installation
16
-
17
- ```bash
18
- npm install @umituz/react-native-sound
19
- ```
20
-
21
- ## Peer Dependencies
22
-
23
- ```bash
24
- npm install expo-av expo-file-system
25
- ```
26
-
27
- ## Quick Start
28
-
29
- ### Basic Usage
30
-
31
- ```typescript
32
- import { useSoundPlayback, Sound } from '@umituz/react-native-sound';
33
-
34
- function MyComponent() {
35
- const { playSound, stopSound, isPlaying } = useSoundPlayback();
36
-
37
- const sound: Sound = {
38
- id: 'ocean-waves',
39
- name: 'Ocean Waves',
40
- filename: 'ocean-waves.mp3',
41
- storageUrl: 'sounds/ocean-waves.mp3', // Or full URL
42
- };
43
-
44
- return (
45
- <Button
46
- onPress={() => {
47
- if (isPlaying(sound.id)) {
48
- stopSound();
49
- } else {
50
- playSound(sound);
51
- }
52
- }}
53
- >
54
- {isPlaying(sound.id) ? 'Stop' : 'Play'}
55
- </Button>
56
- );
57
- }
58
- ```
59
-
60
- ### With Storage Service (Firebase, AWS S3, etc.)
61
-
62
- ```typescript
63
- import { useSoundPlayback, IStorageService } from '@umituz/react-native-sound';
64
- import { getStorage } from 'firebase/storage';
65
- import { ref, getDownloadURL } from 'firebase/storage';
66
-
67
- // Implement storage service
68
- class FirebaseStorageService implements IStorageService {
69
- async getDownloadUrl(storagePath: string): Promise<string> {
70
- const storage = getStorage();
71
- const storageRef = ref(storage, storagePath);
72
- return getDownloadURL(storageRef);
73
- }
74
- }
75
-
76
- function MyComponent() {
77
- const storageService = new FirebaseStorageService();
78
- const { playSound, stopSound } = useSoundPlayback({
79
- storageService,
80
- });
81
-
82
- // ... rest of component
83
- }
84
- ```
85
-
86
- ### Local Assets
87
-
88
- ```typescript
89
- import { useSoundPlayback, Sound } from '@umituz/react-native-sound';
90
- import oceanWavesSound from './assets/sounds/ocean-waves.mp3';
91
-
92
- function MyComponent() {
93
- const { playSound } = useSoundPlayback();
94
-
95
- const sound: Sound = {
96
- id: 'ocean-waves',
97
- name: 'Ocean Waves',
98
- localAsset: oceanWavesSound, // Bundled asset
99
- };
100
-
101
- return <Button onPress={() => playSound(sound)}>Play</Button>;
102
- }
103
- ```
104
-
105
- ### Cache Management
106
-
107
- ```typescript
108
- import { useSoundCache } from '@umituz/react-native-sound';
109
-
110
- function CacheSettings() {
111
- const {
112
- cacheSize,
113
- clearCache,
114
- isCached,
115
- deleteCachedSound,
116
- } = useSoundCache();
117
-
118
- return (
119
- <View>
120
- <Text>Cache Size: {cacheSize.toFixed(2)} MB</Text>
121
- <Button onPress={clearCache}>Clear Cache</Button>
122
- </View>
123
- );
124
- }
125
- ```
126
-
127
- ## API Reference
128
-
129
- ### `useSoundPlayback(options?)`
130
-
131
- Main hook for sound playback.
132
-
133
- #### Options
134
-
135
- - `storageService?: IStorageService` - Storage service for remote URLs
136
- - `autoConfigureAudioSession?: boolean` - Auto-configure audio session (default: true)
137
- - `audioSessionOptions?: {...}` - Audio session configuration
138
-
139
- #### Returns
140
-
141
- - `playSound(sound, options?, onProgress?)` - Play a sound
142
- - `stopSound()` - Stop current sound
143
- - `pauseSound()` - Pause current sound
144
- - `resumeSound()` - Resume paused sound
145
- - `isPlaying(soundId)` - Check if sound is playing
146
- - `playingSoundId` - Currently playing sound ID
147
- - `downloadingSoundId` - Currently downloading sound ID
148
- - `downloadProgress` - Download progress (0-100)
149
- - `isStreaming` - Whether sound is streaming
150
-
151
- ### `useSoundCache()`
152
-
153
- Hook for cache management.
154
-
155
- #### Returns
156
-
157
- - `isCached(sound)` - Check if sound is cached
158
- - `getCachedUri(sound)` - Get cached file URI
159
- - `clearCache()` - Clear all cache
160
- - `getCacheSize()` - Get cache size in MB
161
- - `deleteCachedSound(sound)` - Delete specific cached sound
162
- - `cacheSize` - Current cache size in MB
163
- - `isLoadingCacheSize` - Whether cache size is loading
164
- - `refreshCacheSize()` - Refresh cache size
165
-
166
- ### `Sound` Entity
167
-
168
- ```typescript
169
- interface Sound {
170
- id: string; // Required: Unique identifier
171
- name: string; // Required: Display name
172
- description?: string; // Optional: Description
173
- filename?: string; // Optional: Filename for caching
174
- storageUrl?: string; // Optional: Remote storage path or URL
175
- localAsset?: number; // Optional: Local asset reference
176
- durationSeconds?: number; // Optional: Duration in seconds
177
- isPremium?: boolean; // Optional: Premium flag
178
- category?: string; // Optional: Category
179
- tags?: string[]; // Optional: Tags
180
- metadata?: Record<string, unknown>; // Optional: App-specific metadata
181
- }
182
- ```
183
-
184
- ### `IStorageService` Interface
185
-
186
- ```typescript
187
- interface IStorageService {
188
- getDownloadUrl(storagePath: string): Promise<string>;
189
- }
190
- ```
191
-
192
- Implement this interface for your storage provider (Firebase Storage, AWS S3, etc.).
193
-
194
- ## Architecture
195
-
196
- This package follows Domain-Driven Design (DDD) principles:
197
-
198
- - **Domain Layer**: Entities and interfaces
199
- - **Infrastructure Layer**: Services and storage implementations
200
- - **Presentation Layer**: React hooks
201
-
202
- ### SOLID Principles
203
-
204
- - **Single Responsibility**: Each service has one clear purpose
205
- - **Open/Closed**: Extensible through interfaces
206
- - **Liskov Substitution**: Storage services are interchangeable
207
- - **Interface Segregation**: Small, focused interfaces
208
- - **Dependency Inversion**: Depends on abstractions, not concretions
209
-
210
- ## Examples
211
-
212
- ### Multiple Sounds
213
-
214
- ```typescript
215
- const sounds: Sound[] = [
216
- {
217
- id: 'ocean',
218
- name: 'Ocean Waves',
219
- filename: 'ocean.mp3',
220
- storageUrl: 'sounds/ocean.mp3',
221
- },
222
- {
223
- id: 'rain',
224
- name: 'Rain',
225
- filename: 'rain.mp3',
226
- storageUrl: 'sounds/rain.mp3',
227
- },
228
- ];
229
-
230
- function SoundList() {
231
- const { playSound, isPlaying } = useSoundPlayback();
232
-
233
- return (
234
- <View>
235
- {sounds.map(sound => (
236
- <Button
237
- key={sound.id}
238
- onPress={() => playSound(sound)}
239
- disabled={isPlaying(sound.id)}
240
- >
241
- {sound.name}
242
- </Button>
243
- ))}
244
- </View>
245
- );
246
- }
247
- ```
248
-
249
- ### Download Progress
250
-
251
- ```typescript
252
- function SoundPlayer() {
253
- const { playSound, downloadProgress, downloadingSoundId } = useSoundPlayback();
254
-
255
- const handlePlay = (sound: Sound) => {
256
- playSound(
257
- sound,
258
- { isLooping: true },
259
- (progress) => {
260
- console.log(`Download: ${Math.round(progress * 100)}%`);
261
- }
262
- );
263
- };
264
-
265
- return (
266
- <View>
267
- {downloadingSoundId && (
268
- <ProgressBar value={downloadProgress} />
269
- )}
270
- </View>
271
- );
272
- }
273
- ```
274
-
275
- ## License
276
-
277
- MIT
278
-
279
- ## Author
280
-
281
- Ümit UZ <umit@umituz.com>
282
-
283
-