tunzo-player 1.0.29 → 1.0.31

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/README.md CHANGED
@@ -76,11 +76,16 @@ yarn add tunzo-player
76
76
  | 3 | High (160kbps) |
77
77
  | 4 | Ultra (320kbps) |
78
78
 
79
- | 4 | Ultra (320kbps) |
80
-
81
79
  ## 📱 Native Configuration (Ionic/Capacitor)
82
80
 
83
- To ensure background audio works correctly on Android and iOS (preventing the app from pausing when the screen locks), you must configure your native projects.
81
+ To ensure background audio works correctly on Android and iOS, you need to install the KeepAwake plugin in your main app.
82
+
83
+ ### **Installation**
84
+
85
+ ```bash
86
+ npm install @capacitor-community/keep-awake
87
+ npx cap sync
88
+ ```
84
89
 
85
90
  ### **Android (`android/app/src/main/AndroidManifest.xml`)**
86
91
 
@@ -88,11 +93,8 @@ Add the following permissions inside the `<manifest>` tag:
88
93
 
89
94
  ```xml
90
95
  <uses-permission android:name="android.permission.WAKE_LOCK" />
91
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
92
96
  ```
93
97
 
94
- **Note:** Modern Android versions might require a foreground service notification to keep the audio alive indefinitely. The `MediaSession` API implemented in this package helps, but for guaranteed persistence, consider using a native audio plugin if issues persist.
95
-
96
98
  ### **iOS (`ios/App/App/Info.plist`)**
97
99
 
98
100
  Add `audio` to the `UIBackgroundModes` key to allow background playback:
@@ -104,8 +106,11 @@ Add `audio` to the `UIBackgroundModes` key to allow background playback:
104
106
  </array>
105
107
  ```
106
108
 
109
+ **Note:** The player uses HTML5 Audio with MediaSession API for lock screen controls. This works with MP4/AAC audio streams (like JioSaavn) on both Android and iOS.
110
+
107
111
  ## 🤝 Contributing
108
112
 
109
113
  Contributions are welcome! Please open an issue or submit a pull request.
110
114
 
111
115
  # tunzo-player
116
+
@@ -206,33 +206,43 @@ class Player {
206
206
  }
207
207
  }
208
208
  static updateMediaSessionMetadata(song) {
209
- var _a;
209
+ var _a, _b;
210
210
  if ('mediaSession' in navigator) {
211
+ // Extract artwork from image array
211
212
  const artwork = [];
212
- if (song.image) {
213
- if (Array.isArray(song.image)) {
214
- song.image.forEach((img) => {
215
- let src = img.link || img.url || (typeof img === 'string' ? img : '');
216
- if (src) {
217
- if (src.startsWith('http://')) {
218
- src = src.replace('http://', 'https://');
219
- }
220
- artwork.push({ src, sizes: '500x500', type: 'image/jpeg' });
221
- }
222
- });
223
- }
224
- else if (typeof song.image === 'string') {
225
- let src = song.image;
213
+ if (song.image && Array.isArray(song.image)) {
214
+ // Get the highest quality image (last in array, usually 500x500)
215
+ const highQualityImage = song.image[song.image.length - 1];
216
+ if (highQualityImage && highQualityImage.url) {
217
+ let src = highQualityImage.url;
226
218
  if (src.startsWith('http://')) {
227
219
  src = src.replace('http://', 'https://');
228
220
  }
229
- artwork.push({ src: src, sizes: '500x500', type: 'image/jpeg' });
221
+ // Skip placeholder images
222
+ if (!src.includes('_i/share-image')) {
223
+ artwork.push({
224
+ src,
225
+ sizes: highQualityImage.quality || '500x500',
226
+ type: 'image/jpeg'
227
+ });
228
+ }
230
229
  }
231
230
  }
231
+ // Extract artist name from artists.primary array
232
+ let artistName = 'Unknown Artist';
233
+ if (((_a = song.artists) === null || _a === void 0 ? void 0 : _a.primary) && Array.isArray(song.artists.primary) && song.artists.primary.length > 0) {
234
+ artistName = song.artists.primary.map((artist) => artist.name).join(', ');
235
+ }
236
+ else if (song.primaryArtists) {
237
+ artistName = song.primaryArtists;
238
+ }
239
+ else if (song.artist) {
240
+ artistName = song.artist;
241
+ }
232
242
  navigator.mediaSession.metadata = new MediaMetadata({
233
243
  title: song.name || song.title || 'Unknown Title',
234
- artist: song.primaryArtists || song.artist || 'Unknown Artist',
235
- album: ((_a = song.album) === null || _a === void 0 ? void 0 : _a.name) || song.album || 'Unknown Album',
244
+ artist: artistName,
245
+ album: ((_b = song.album) === null || _b === void 0 ? void 0 : _b.name) || 'Unknown Album',
236
246
  artwork: artwork.length > 0 ? artwork : undefined
237
247
  });
238
248
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tunzo-player",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "A music playback service for Angular and Ionic apps with native audio control support.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -250,31 +250,41 @@ export class Player {
250
250
 
251
251
  private static updateMediaSessionMetadata(song: any) {
252
252
  if ('mediaSession' in navigator) {
253
+ // Extract artwork from image array
253
254
  const artwork = [];
254
- if (song.image) {
255
- if (Array.isArray(song.image)) {
256
- song.image.forEach((img: any) => {
257
- let src = img.link || img.url || (typeof img === 'string' ? img : '');
258
- if (src) {
259
- if (src.startsWith('http://')) {
260
- src = src.replace('http://', 'https://');
261
- }
262
- artwork.push({ src, sizes: '500x500', type: 'image/jpeg' });
263
- }
264
- });
265
- } else if (typeof song.image === 'string') {
266
- let src = song.image;
255
+ if (song.image && Array.isArray(song.image)) {
256
+ // Get the highest quality image (last in array, usually 500x500)
257
+ const highQualityImage = song.image[song.image.length - 1];
258
+ if (highQualityImage && highQualityImage.url) {
259
+ let src = highQualityImage.url;
267
260
  if (src.startsWith('http://')) {
268
261
  src = src.replace('http://', 'https://');
269
262
  }
270
- artwork.push({ src: src, sizes: '500x500', type: 'image/jpeg' });
263
+ // Skip placeholder images
264
+ if (!src.includes('_i/share-image')) {
265
+ artwork.push({
266
+ src,
267
+ sizes: highQualityImage.quality || '500x500',
268
+ type: 'image/jpeg'
269
+ });
270
+ }
271
271
  }
272
272
  }
273
273
 
274
+ // Extract artist name from artists.primary array
275
+ let artistName = 'Unknown Artist';
276
+ if (song.artists?.primary && Array.isArray(song.artists.primary) && song.artists.primary.length > 0) {
277
+ artistName = song.artists.primary.map((artist: any) => artist.name).join(', ');
278
+ } else if (song.primaryArtists) {
279
+ artistName = song.primaryArtists;
280
+ } else if (song.artist) {
281
+ artistName = song.artist;
282
+ }
283
+
274
284
  navigator.mediaSession.metadata = new MediaMetadata({
275
285
  title: song.name || song.title || 'Unknown Title',
276
- artist: song.primaryArtists || song.artist || 'Unknown Artist',
277
- album: song.album?.name || song.album || 'Unknown Album',
286
+ artist: artistName,
287
+ album: song.album?.name || 'Unknown Album',
278
288
  artwork: artwork.length > 0 ? artwork : undefined
279
289
  });
280
290
  }