tunzo-player 1.0.25 → 1.0.27
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/dist/core/player.d.ts +2 -0
- package/dist/core/player.js +50 -0
- package/package.json +3 -1
- package/src/core/player.ts +38 -0
package/dist/core/player.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export declare class Player {
|
|
|
37
37
|
static setQuality(index: number): void;
|
|
38
38
|
static getQueue(): any[];
|
|
39
39
|
static getPlaylist(): any[];
|
|
40
|
+
private static enableBackgroundMode;
|
|
41
|
+
private static disableBackgroundMode;
|
|
40
42
|
private static setupMediaSession;
|
|
41
43
|
private static updateMediaSessionMetadata;
|
|
42
44
|
private static updatePositionState;
|
package/dist/core/player.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.Player = void 0;
|
|
4
13
|
const rxjs_1 = require("rxjs");
|
|
14
|
+
const capacitor_background_mode_1 = require("@anuradev/capacitor-background-mode");
|
|
15
|
+
const keep_awake_1 = require("@capacitor-community/keep-awake");
|
|
5
16
|
class Player {
|
|
6
17
|
/** Initialize with playlist and quality */
|
|
7
18
|
static initialize(playlist, quality = 3) {
|
|
@@ -35,6 +46,7 @@ class Player {
|
|
|
35
46
|
this.audio.play().then(() => {
|
|
36
47
|
this.isPlaying = true;
|
|
37
48
|
this.updateMediaSessionMetadata(song);
|
|
49
|
+
this.enableBackgroundMode();
|
|
38
50
|
if ('mediaSession' in navigator) {
|
|
39
51
|
navigator.mediaSession.playbackState = 'playing';
|
|
40
52
|
}
|
|
@@ -79,6 +91,7 @@ class Player {
|
|
|
79
91
|
static pause() {
|
|
80
92
|
this.audio.pause();
|
|
81
93
|
this.isPlaying = false;
|
|
94
|
+
this.disableBackgroundMode();
|
|
82
95
|
if ('mediaSession' in navigator) {
|
|
83
96
|
navigator.mediaSession.playbackState = 'paused';
|
|
84
97
|
}
|
|
@@ -181,6 +194,43 @@ class Player {
|
|
|
181
194
|
return this.playlist;
|
|
182
195
|
}
|
|
183
196
|
// -------------------------------------------------------------------------
|
|
197
|
+
// Capacitor Background Mode & Keep Awake
|
|
198
|
+
// -------------------------------------------------------------------------
|
|
199
|
+
static enableBackgroundMode() {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
try {
|
|
202
|
+
yield keep_awake_1.KeepAwake.keepAwake();
|
|
203
|
+
yield capacitor_background_mode_1.BackgroundMode.enable({
|
|
204
|
+
title: "Tunzo Player",
|
|
205
|
+
text: "Playing music in background",
|
|
206
|
+
icon: "ic_launcher",
|
|
207
|
+
color: "042730",
|
|
208
|
+
resume: true,
|
|
209
|
+
hidden: false,
|
|
210
|
+
bigText: true,
|
|
211
|
+
disableWebViewOptimization: true
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
// Plugin might not be installed or on web
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
static disableBackgroundMode() {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
try {
|
|
222
|
+
yield keep_awake_1.KeepAwake.allowSleep();
|
|
223
|
+
// We might want to keep background mode enabled if we want to resume later,
|
|
224
|
+
// but for battery saving, we can disable it or move to background.
|
|
225
|
+
// await BackgroundMode.disable();
|
|
226
|
+
yield capacitor_background_mode_1.BackgroundMode.moveToBackground();
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
// Plugin might not be installed or on web
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
// -------------------------------------------------------------------------
|
|
184
234
|
// Native Media Session (Lock Screen Controls)
|
|
185
235
|
// -------------------------------------------------------------------------
|
|
186
236
|
static setupMediaSession() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tunzo-player",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
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",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@anuradev/capacitor-background-mode": "^7.2.1",
|
|
33
|
+
"@capacitor-community/keep-awake": "^7.1.0",
|
|
32
34
|
"rxjs": "^7.8.2"
|
|
33
35
|
}
|
|
34
36
|
}
|
package/src/core/player.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { BackgroundMode } from '@anuradev/capacitor-background-mode';
|
|
3
|
+
import { KeepAwake } from '@capacitor-community/keep-awake';
|
|
2
4
|
|
|
3
5
|
export class Player {
|
|
4
6
|
private static audio = new Audio();
|
|
@@ -49,6 +51,7 @@ export class Player {
|
|
|
49
51
|
this.audio.play().then(() => {
|
|
50
52
|
this.isPlaying = true;
|
|
51
53
|
this.updateMediaSessionMetadata(song);
|
|
54
|
+
this.enableBackgroundMode();
|
|
52
55
|
if ('mediaSession' in navigator) {
|
|
53
56
|
navigator.mediaSession.playbackState = 'playing';
|
|
54
57
|
}
|
|
@@ -101,6 +104,7 @@ export class Player {
|
|
|
101
104
|
static pause() {
|
|
102
105
|
this.audio.pause();
|
|
103
106
|
this.isPlaying = false;
|
|
107
|
+
this.disableBackgroundMode();
|
|
104
108
|
if ('mediaSession' in navigator) {
|
|
105
109
|
navigator.mediaSession.playbackState = 'paused';
|
|
106
110
|
}
|
|
@@ -221,6 +225,40 @@ export class Player {
|
|
|
221
225
|
return this.playlist;
|
|
222
226
|
}
|
|
223
227
|
|
|
228
|
+
// -------------------------------------------------------------------------
|
|
229
|
+
// Capacitor Background Mode & Keep Awake
|
|
230
|
+
// -------------------------------------------------------------------------
|
|
231
|
+
|
|
232
|
+
private static async enableBackgroundMode() {
|
|
233
|
+
try {
|
|
234
|
+
await KeepAwake.keepAwake();
|
|
235
|
+
await BackgroundMode.enable({
|
|
236
|
+
title: "Tunzo Player",
|
|
237
|
+
text: "Playing music in background",
|
|
238
|
+
icon: "ic_launcher",
|
|
239
|
+
color: "042730",
|
|
240
|
+
resume: true,
|
|
241
|
+
hidden: false,
|
|
242
|
+
bigText: true,
|
|
243
|
+
disableWebViewOptimization: true
|
|
244
|
+
});
|
|
245
|
+
} catch (err) {
|
|
246
|
+
// Plugin might not be installed or on web
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private static async disableBackgroundMode() {
|
|
251
|
+
try {
|
|
252
|
+
await KeepAwake.allowSleep();
|
|
253
|
+
// We might want to keep background mode enabled if we want to resume later,
|
|
254
|
+
// but for battery saving, we can disable it or move to background.
|
|
255
|
+
// await BackgroundMode.disable();
|
|
256
|
+
await BackgroundMode.moveToBackground();
|
|
257
|
+
} catch (err) {
|
|
258
|
+
// Plugin might not be installed or on web
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
224
262
|
// -------------------------------------------------------------------------
|
|
225
263
|
// Native Media Session (Lock Screen Controls)
|
|
226
264
|
// -------------------------------------------------------------------------
|