@capgo/capacitor-media-session 7.0.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.
Files changed (34) hide show
  1. package/CapgoMediaSession.podspec +17 -0
  2. package/Package.swift +28 -0
  3. package/README.md +164 -0
  4. package/android/build.gradle +60 -0
  5. package/android/src/main/AndroidManifest.xml +26 -0
  6. package/android/src/main/java/com/capgo/mediasession/MediaSessionCallback.java +55 -0
  7. package/android/src/main/java/com/capgo/mediasession/MediaSessionPlugin.java +277 -0
  8. package/android/src/main/java/com/capgo/mediasession/MediaSessionService.java +366 -0
  9. package/android/src/main/res/.gitkeep +0 -0
  10. package/android/src/main/res/drawable/ic_baseline_forward_30_24.xml +16 -0
  11. package/android/src/main/res/drawable/ic_baseline_pause_24.xml +10 -0
  12. package/android/src/main/res/drawable/ic_baseline_play_arrow_24.xml +10 -0
  13. package/android/src/main/res/drawable/ic_baseline_replay_30_24.xml +16 -0
  14. package/android/src/main/res/drawable/ic_baseline_skip_next_24.xml +10 -0
  15. package/android/src/main/res/drawable/ic_baseline_skip_previous_24.xml +10 -0
  16. package/android/src/main/res/drawable/ic_baseline_stop_24.xml +10 -0
  17. package/android/src/main/res/drawable/ic_baseline_volume_up_24.xml +10 -0
  18. package/dist/docs.json +326 -0
  19. package/dist/esm/definitions.d.ts +48 -0
  20. package/dist/esm/definitions.js +2 -0
  21. package/dist/esm/definitions.js.map +1 -0
  22. package/dist/esm/index.d.ts +4 -0
  23. package/dist/esm/index.js +8 -0
  24. package/dist/esm/index.js.map +1 -0
  25. package/dist/esm/web.d.ts +8 -0
  26. package/dist/esm/web.js +38 -0
  27. package/dist/esm/web.js.map +1 -0
  28. package/dist/plugin.cjs.js +53 -0
  29. package/dist/plugin.cjs.js.map +1 -0
  30. package/dist/plugin.js +56 -0
  31. package/dist/plugin.js.map +1 -0
  32. package/ios/Sources/MediaSessionPlugin/MediaSessionPlugin.swift +9 -0
  33. package/ios/Tests/MediaSessionPluginTests/MediaSessionPluginTests.swift +15 -0
  34. package/package.json +83 -0
package/dist/docs.json ADDED
@@ -0,0 +1,326 @@
1
+ {
2
+ "api": {
3
+ "name": "MediaSessionPlugin",
4
+ "slug": "mediasessionplugin",
5
+ "docs": "",
6
+ "tags": [],
7
+ "methods": [
8
+ {
9
+ "name": "setMetadata",
10
+ "signature": "(options: MetadataOptions) => Promise<void>",
11
+ "parameters": [
12
+ {
13
+ "name": "options",
14
+ "docs": "",
15
+ "type": "MetadataOptions"
16
+ }
17
+ ],
18
+ "returns": "Promise<void>",
19
+ "tags": [],
20
+ "docs": "Sets metadata of the currently playing media.",
21
+ "complexTypes": [
22
+ "MetadataOptions"
23
+ ],
24
+ "slug": "setmetadata"
25
+ },
26
+ {
27
+ "name": "setPlaybackState",
28
+ "signature": "(options: PlaybackStateOptions) => Promise<void>",
29
+ "parameters": [
30
+ {
31
+ "name": "options",
32
+ "docs": "",
33
+ "type": "PlaybackStateOptions"
34
+ }
35
+ ],
36
+ "returns": "Promise<void>",
37
+ "tags": [],
38
+ "docs": "Updates the playback state of the media session.",
39
+ "complexTypes": [
40
+ "PlaybackStateOptions"
41
+ ],
42
+ "slug": "setplaybackstate"
43
+ },
44
+ {
45
+ "name": "setActionHandler",
46
+ "signature": "(options: ActionHandlerOptions, handler: ActionHandler | null) => Promise<void>",
47
+ "parameters": [
48
+ {
49
+ "name": "options",
50
+ "docs": "",
51
+ "type": "ActionHandlerOptions"
52
+ },
53
+ {
54
+ "name": "handler",
55
+ "docs": "",
56
+ "type": "ActionHandler | null"
57
+ }
58
+ ],
59
+ "returns": "Promise<void>",
60
+ "tags": [],
61
+ "docs": "Registers a handler for a media session action.",
62
+ "complexTypes": [
63
+ "ActionHandlerOptions",
64
+ "ActionHandler"
65
+ ],
66
+ "slug": "setactionhandler"
67
+ },
68
+ {
69
+ "name": "setPositionState",
70
+ "signature": "(options: PositionStateOptions) => Promise<void>",
71
+ "parameters": [
72
+ {
73
+ "name": "options",
74
+ "docs": "",
75
+ "type": "PositionStateOptions"
76
+ }
77
+ ],
78
+ "returns": "Promise<void>",
79
+ "tags": [],
80
+ "docs": "Updates position state for the active media session.",
81
+ "complexTypes": [
82
+ "PositionStateOptions"
83
+ ],
84
+ "slug": "setpositionstate"
85
+ }
86
+ ],
87
+ "properties": []
88
+ },
89
+ "interfaces": [
90
+ {
91
+ "name": "MetadataOptions",
92
+ "slug": "metadataoptions",
93
+ "docs": "",
94
+ "tags": [],
95
+ "methods": [],
96
+ "properties": [
97
+ {
98
+ "name": "album",
99
+ "tags": [],
100
+ "docs": "",
101
+ "complexTypes": [],
102
+ "type": "string | undefined"
103
+ },
104
+ {
105
+ "name": "artist",
106
+ "tags": [],
107
+ "docs": "",
108
+ "complexTypes": [],
109
+ "type": "string | undefined"
110
+ },
111
+ {
112
+ "name": "artwork",
113
+ "tags": [],
114
+ "docs": "",
115
+ "complexTypes": [
116
+ "MediaImage"
117
+ ],
118
+ "type": "MediaImage[] | undefined"
119
+ },
120
+ {
121
+ "name": "title",
122
+ "tags": [],
123
+ "docs": "",
124
+ "complexTypes": [],
125
+ "type": "string | undefined"
126
+ }
127
+ ]
128
+ },
129
+ {
130
+ "name": "MediaImage",
131
+ "slug": "mediaimage",
132
+ "docs": "",
133
+ "tags": [],
134
+ "methods": [],
135
+ "properties": [
136
+ {
137
+ "name": "src",
138
+ "tags": [],
139
+ "docs": "",
140
+ "complexTypes": [],
141
+ "type": "string"
142
+ },
143
+ {
144
+ "name": "sizes",
145
+ "tags": [],
146
+ "docs": "",
147
+ "complexTypes": [],
148
+ "type": "string | undefined"
149
+ },
150
+ {
151
+ "name": "type",
152
+ "tags": [],
153
+ "docs": "",
154
+ "complexTypes": [],
155
+ "type": "string | undefined"
156
+ }
157
+ ]
158
+ },
159
+ {
160
+ "name": "PlaybackStateOptions",
161
+ "slug": "playbackstateoptions",
162
+ "docs": "",
163
+ "tags": [],
164
+ "methods": [],
165
+ "properties": [
166
+ {
167
+ "name": "playbackState",
168
+ "tags": [],
169
+ "docs": "",
170
+ "complexTypes": [
171
+ "MediaSessionPlaybackState"
172
+ ],
173
+ "type": "MediaSessionPlaybackState"
174
+ }
175
+ ]
176
+ },
177
+ {
178
+ "name": "ActionHandlerOptions",
179
+ "slug": "actionhandleroptions",
180
+ "docs": "",
181
+ "tags": [],
182
+ "methods": [],
183
+ "properties": [
184
+ {
185
+ "name": "action",
186
+ "tags": [],
187
+ "docs": "",
188
+ "complexTypes": [
189
+ "MediaSessionAction"
190
+ ],
191
+ "type": "MediaSessionAction"
192
+ }
193
+ ]
194
+ },
195
+ {
196
+ "name": "ActionDetails",
197
+ "slug": "actiondetails",
198
+ "docs": "",
199
+ "tags": [],
200
+ "methods": [],
201
+ "properties": [
202
+ {
203
+ "name": "action",
204
+ "tags": [],
205
+ "docs": "",
206
+ "complexTypes": [
207
+ "MediaSessionAction"
208
+ ],
209
+ "type": "MediaSessionAction"
210
+ },
211
+ {
212
+ "name": "seekTime",
213
+ "tags": [],
214
+ "docs": "",
215
+ "complexTypes": [],
216
+ "type": "number | null | undefined"
217
+ }
218
+ ]
219
+ },
220
+ {
221
+ "name": "PositionStateOptions",
222
+ "slug": "positionstateoptions",
223
+ "docs": "",
224
+ "tags": [],
225
+ "methods": [],
226
+ "properties": [
227
+ {
228
+ "name": "duration",
229
+ "tags": [],
230
+ "docs": "",
231
+ "complexTypes": [],
232
+ "type": "number | undefined"
233
+ },
234
+ {
235
+ "name": "playbackRate",
236
+ "tags": [],
237
+ "docs": "",
238
+ "complexTypes": [],
239
+ "type": "number | undefined"
240
+ },
241
+ {
242
+ "name": "position",
243
+ "tags": [],
244
+ "docs": "",
245
+ "complexTypes": [],
246
+ "type": "number | undefined"
247
+ }
248
+ ]
249
+ }
250
+ ],
251
+ "enums": [],
252
+ "typeAliases": [
253
+ {
254
+ "name": "MediaSessionPlaybackState",
255
+ "slug": "mediasessionplaybackstate",
256
+ "docs": "",
257
+ "types": [
258
+ {
259
+ "text": "'none'",
260
+ "complexTypes": []
261
+ },
262
+ {
263
+ "text": "'paused'",
264
+ "complexTypes": []
265
+ },
266
+ {
267
+ "text": "'playing'",
268
+ "complexTypes": []
269
+ }
270
+ ]
271
+ },
272
+ {
273
+ "name": "MediaSessionAction",
274
+ "slug": "mediasessionaction",
275
+ "docs": "",
276
+ "types": [
277
+ {
278
+ "text": "'play'",
279
+ "complexTypes": []
280
+ },
281
+ {
282
+ "text": "'pause'",
283
+ "complexTypes": []
284
+ },
285
+ {
286
+ "text": "'seekbackward'",
287
+ "complexTypes": []
288
+ },
289
+ {
290
+ "text": "'seekforward'",
291
+ "complexTypes": []
292
+ },
293
+ {
294
+ "text": "'previoustrack'",
295
+ "complexTypes": []
296
+ },
297
+ {
298
+ "text": "'nexttrack'",
299
+ "complexTypes": []
300
+ },
301
+ {
302
+ "text": "'seekto'",
303
+ "complexTypes": []
304
+ },
305
+ {
306
+ "text": "'stop'",
307
+ "complexTypes": []
308
+ }
309
+ ]
310
+ },
311
+ {
312
+ "name": "ActionHandler",
313
+ "slug": "actionhandler",
314
+ "docs": "",
315
+ "types": [
316
+ {
317
+ "text": "(details: ActionDetails): void",
318
+ "complexTypes": [
319
+ "ActionDetails"
320
+ ]
321
+ }
322
+ ]
323
+ }
324
+ ],
325
+ "pluginConfigs": []
326
+ }
@@ -0,0 +1,48 @@
1
+ export interface MediaImage {
2
+ src: string;
3
+ sizes?: string;
4
+ type?: string;
5
+ }
6
+ export declare type MediaSessionPlaybackState = 'none' | 'paused' | 'playing';
7
+ export declare type MediaSessionAction = 'play' | 'pause' | 'seekbackward' | 'seekforward' | 'previoustrack' | 'nexttrack' | 'seekto' | 'stop';
8
+ export interface MetadataOptions {
9
+ album?: string;
10
+ artist?: string;
11
+ artwork?: MediaImage[];
12
+ title?: string;
13
+ }
14
+ export interface PlaybackStateOptions {
15
+ playbackState: MediaSessionPlaybackState;
16
+ }
17
+ export interface ActionHandlerOptions {
18
+ action: MediaSessionAction;
19
+ }
20
+ export declare type ActionHandler = (details: ActionDetails) => void;
21
+ interface ActionDetails {
22
+ action: MediaSessionAction;
23
+ seekTime?: number | null;
24
+ }
25
+ export interface PositionStateOptions {
26
+ duration?: number;
27
+ playbackRate?: number;
28
+ position?: number;
29
+ }
30
+ export interface MediaSessionPlugin {
31
+ /**
32
+ * Sets metadata of the currently playing media.
33
+ */
34
+ setMetadata(options: MetadataOptions): Promise<void>;
35
+ /**
36
+ * Updates the playback state of the media session.
37
+ */
38
+ setPlaybackState(options: PlaybackStateOptions): Promise<void>;
39
+ /**
40
+ * Registers a handler for a media session action.
41
+ */
42
+ setActionHandler(options: ActionHandlerOptions, handler: ActionHandler | null): Promise<void>;
43
+ /**
44
+ * Updates position state for the active media session.
45
+ */
46
+ setPositionState(options: PositionStateOptions): Promise<void>;
47
+ }
48
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface MediaImage {\n src: string;\n sizes?: string;\n type?: string;\n}\n\nexport type MediaSessionPlaybackState = 'none' | 'paused' | 'playing';\n\nexport type MediaSessionAction =\n | 'play'\n | 'pause'\n | 'seekbackward'\n | 'seekforward'\n | 'previoustrack'\n | 'nexttrack'\n | 'seekto'\n | 'stop';\n\nexport interface MetadataOptions {\n album?: string;\n artist?: string;\n artwork?: MediaImage[];\n title?: string;\n}\n\nexport interface PlaybackStateOptions {\n playbackState: MediaSessionPlaybackState;\n}\n\nexport interface ActionHandlerOptions {\n action: MediaSessionAction;\n}\n\nexport type ActionHandler = (details: ActionDetails) => void;\n\ninterface ActionDetails {\n action: MediaSessionAction;\n seekTime?: number | null;\n}\n\nexport interface PositionStateOptions {\n duration?: number;\n playbackRate?: number;\n position?: number;\n}\n\nexport interface MediaSessionPlugin {\n /**\n * Sets metadata of the currently playing media.\n */\n setMetadata(options: MetadataOptions): Promise<void>;\n /**\n * Updates the playback state of the media session.\n */\n setPlaybackState(options: PlaybackStateOptions): Promise<void>;\n /**\n * Registers a handler for a media session action.\n */\n setActionHandler(options: ActionHandlerOptions, handler: ActionHandler | null): Promise<void>;\n /**\n * Updates position state for the active media session.\n */\n setPositionState(options: PositionStateOptions): Promise<void>;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { MediaSessionPlugin } from './definitions';
2
+ declare const MediaSession: MediaSessionPlugin;
3
+ export * from './definitions';
4
+ export { MediaSession };
@@ -0,0 +1,8 @@
1
+ import { registerPlugin } from '@capacitor/core';
2
+ const MediaSession = registerPlugin('MediaSession', {
3
+ web: () => import('./web').then((m) => new m.MediaSessionWeb()),
4
+ ios: () => import('./web').then((m) => new m.MediaSessionWeb()),
5
+ });
6
+ export * from './definitions';
7
+ export { MediaSession };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IAC/D,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAChE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { MediaSessionPlugin } from './definitions';\n\nconst MediaSession = registerPlugin<MediaSessionPlugin>('MediaSession', {\n web: () => import('./web').then((m) => new m.MediaSessionWeb()),\n ios: () => import('./web').then((m) => new m.MediaSessionWeb()),\n});\n\nexport * from './definitions';\nexport { MediaSession };\n"]}
@@ -0,0 +1,8 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ import type { ActionHandler, ActionHandlerOptions, MediaSessionPlugin, MetadataOptions, PlaybackStateOptions, PositionStateOptions } from './definitions';
3
+ export declare class MediaSessionWeb extends WebPlugin implements MediaSessionPlugin {
4
+ setMetadata(options: MetadataOptions): Promise<void>;
5
+ setPlaybackState(options: PlaybackStateOptions): Promise<void>;
6
+ setActionHandler(options: ActionHandlerOptions, handler: ActionHandler | null): Promise<void>;
7
+ setPositionState(options: PositionStateOptions): Promise<void>;
8
+ }
@@ -0,0 +1,38 @@
1
+ import { WebPlugin } from '@capacitor/core';
2
+ export class MediaSessionWeb extends WebPlugin {
3
+ async setMetadata(options) {
4
+ const mediaSession = navigator.mediaSession;
5
+ if (!mediaSession) {
6
+ throw this.unavailable('Media Session API not available in this browser.');
7
+ }
8
+ const MediaMetadataCtor = window.MediaMetadata;
9
+ if (MediaMetadataCtor) {
10
+ mediaSession.metadata = new MediaMetadataCtor(options);
11
+ }
12
+ else {
13
+ mediaSession.metadata = options;
14
+ }
15
+ }
16
+ async setPlaybackState(options) {
17
+ const mediaSession = navigator.mediaSession;
18
+ if (!mediaSession) {
19
+ throw this.unavailable('Media Session API not available in this browser.');
20
+ }
21
+ mediaSession.playbackState = options.playbackState;
22
+ }
23
+ async setActionHandler(options, handler) {
24
+ const mediaSession = navigator.mediaSession;
25
+ if (!mediaSession) {
26
+ throw this.unavailable('Media Session API not available in this browser.');
27
+ }
28
+ mediaSession.setActionHandler(options.action, handler);
29
+ }
30
+ async setPositionState(options) {
31
+ const mediaSession = navigator.mediaSession;
32
+ if (!mediaSession) {
33
+ throw this.unavailable('Media Session API not available in this browser.');
34
+ }
35
+ mediaSession.setPositionState(options);
36
+ }
37
+ }
38
+ //# sourceMappingURL=web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAW5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,KAAK,CAAC,WAAW,CAAC,OAAwB;QACxC,MAAM,YAAY,GAAI,SAAiB,CAAC,YAAY,CAAC;QACrD,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;SAC5E;QAED,MAAM,iBAAiB,GAAI,MAAc,CAAC,aAAa,CAAC;QACxD,IAAI,iBAAiB,EAAE;YACrB,YAAY,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;SACxD;aAAM;YACL,YAAY,CAAC,QAAQ,GAAG,OAAO,CAAC;SACjC;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAA6B;QAClD,MAAM,YAAY,GAAI,SAAiB,CAAC,YAAY,CAAC;QACrD,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;SAC5E;QACD,YAAY,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAA6B,EAAE,OAA6B;QACjF,MAAM,YAAY,GAAI,SAAiB,CAAC,YAAY,CAAC;QACrD,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;SAC5E;QACD,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAA6B;QAClD,MAAM,YAAY,GAAI,SAAiB,CAAC,YAAY,CAAC;QACrD,IAAI,CAAC,YAAY,EAAE;YACjB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;SAC5E;QACD,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n ActionHandler,\n ActionHandlerOptions,\n MediaSessionPlugin,\n MetadataOptions,\n PlaybackStateOptions,\n PositionStateOptions,\n} from './definitions';\n\nexport class MediaSessionWeb extends WebPlugin implements MediaSessionPlugin {\n async setMetadata(options: MetadataOptions): Promise<void> {\n const mediaSession = (navigator as any).mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n\n const MediaMetadataCtor = (window as any).MediaMetadata;\n if (MediaMetadataCtor) {\n mediaSession.metadata = new MediaMetadataCtor(options);\n } else {\n mediaSession.metadata = options;\n }\n }\n\n async setPlaybackState(options: PlaybackStateOptions): Promise<void> {\n const mediaSession = (navigator as any).mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.playbackState = options.playbackState;\n }\n\n async setActionHandler(options: ActionHandlerOptions, handler: ActionHandler | null): Promise<void> {\n const mediaSession = (navigator as any).mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.setActionHandler(options.action, handler);\n }\n\n async setPositionState(options: PositionStateOptions): Promise<void> {\n const mediaSession = (navigator as any).mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.setPositionState(options);\n }\n}\n"]}
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var core = require('@capacitor/core');
4
+
5
+ const MediaSession = core.registerPlugin('MediaSession', {
6
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.MediaSessionWeb()),
7
+ ios: () => Promise.resolve().then(function () { return web; }).then((m) => new m.MediaSessionWeb()),
8
+ });
9
+
10
+ class MediaSessionWeb extends core.WebPlugin {
11
+ async setMetadata(options) {
12
+ const mediaSession = navigator.mediaSession;
13
+ if (!mediaSession) {
14
+ throw this.unavailable('Media Session API not available in this browser.');
15
+ }
16
+ const MediaMetadataCtor = window.MediaMetadata;
17
+ if (MediaMetadataCtor) {
18
+ mediaSession.metadata = new MediaMetadataCtor(options);
19
+ }
20
+ else {
21
+ mediaSession.metadata = options;
22
+ }
23
+ }
24
+ async setPlaybackState(options) {
25
+ const mediaSession = navigator.mediaSession;
26
+ if (!mediaSession) {
27
+ throw this.unavailable('Media Session API not available in this browser.');
28
+ }
29
+ mediaSession.playbackState = options.playbackState;
30
+ }
31
+ async setActionHandler(options, handler) {
32
+ const mediaSession = navigator.mediaSession;
33
+ if (!mediaSession) {
34
+ throw this.unavailable('Media Session API not available in this browser.');
35
+ }
36
+ mediaSession.setActionHandler(options.action, handler);
37
+ }
38
+ async setPositionState(options) {
39
+ const mediaSession = navigator.mediaSession;
40
+ if (!mediaSession) {
41
+ throw this.unavailable('Media Session API not available in this browser.');
42
+ }
43
+ mediaSession.setPositionState(options);
44
+ }
45
+ }
46
+
47
+ var web = /*#__PURE__*/Object.freeze({
48
+ __proto__: null,
49
+ MediaSessionWeb: MediaSessionWeb
50
+ });
51
+
52
+ exports.MediaSession = MediaSession;
53
+ //# sourceMappingURL=plugin.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst MediaSession = registerPlugin('MediaSession', {\n web: () => import('./web').then((m) => new m.MediaSessionWeb()),\n ios: () => import('./web').then((m) => new m.MediaSessionWeb()),\n});\nexport * from './definitions';\nexport { MediaSession };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class MediaSessionWeb extends WebPlugin {\n async setMetadata(options) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n const MediaMetadataCtor = window.MediaMetadata;\n if (MediaMetadataCtor) {\n mediaSession.metadata = new MediaMetadataCtor(options);\n }\n else {\n mediaSession.metadata = options;\n }\n }\n async setPlaybackState(options) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.playbackState = options.playbackState;\n }\n async setActionHandler(options, handler) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.setActionHandler(options.action, handler);\n }\n async setPositionState(options) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.setPositionState(options);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACnE,CAAC;;ACHM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;AACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;AAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;AACtF,QAAQ;AACR,QAAQ,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa;AACtD,QAAQ,IAAI,iBAAiB,EAAE;AAC/B,YAAY,YAAY,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC;AAClE,QAAQ;AACR,aAAa;AACb,YAAY,YAAY,CAAC,QAAQ,GAAG,OAAO;AAC3C,QAAQ;AACR,IAAI;AACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE;AACpC,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;AACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;AAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;AACtF,QAAQ;AACR,QAAQ,YAAY,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa;AAC1D,IAAI;AACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE;AAC7C,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;AACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;AAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;AACtF,QAAQ;AACR,QAAQ,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;AAC9D,IAAI;AACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE;AACpC,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;AACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;AAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;AACtF,QAAQ;AACR,QAAQ,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC;AAC9C,IAAI;AACJ;;;;;;;;;"}
package/dist/plugin.js ADDED
@@ -0,0 +1,56 @@
1
+ var capacitorMediaSession = (function (exports, core) {
2
+ 'use strict';
3
+
4
+ const MediaSession = core.registerPlugin('MediaSession', {
5
+ web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.MediaSessionWeb()),
6
+ ios: () => Promise.resolve().then(function () { return web; }).then((m) => new m.MediaSessionWeb()),
7
+ });
8
+
9
+ class MediaSessionWeb extends core.WebPlugin {
10
+ async setMetadata(options) {
11
+ const mediaSession = navigator.mediaSession;
12
+ if (!mediaSession) {
13
+ throw this.unavailable('Media Session API not available in this browser.');
14
+ }
15
+ const MediaMetadataCtor = window.MediaMetadata;
16
+ if (MediaMetadataCtor) {
17
+ mediaSession.metadata = new MediaMetadataCtor(options);
18
+ }
19
+ else {
20
+ mediaSession.metadata = options;
21
+ }
22
+ }
23
+ async setPlaybackState(options) {
24
+ const mediaSession = navigator.mediaSession;
25
+ if (!mediaSession) {
26
+ throw this.unavailable('Media Session API not available in this browser.');
27
+ }
28
+ mediaSession.playbackState = options.playbackState;
29
+ }
30
+ async setActionHandler(options, handler) {
31
+ const mediaSession = navigator.mediaSession;
32
+ if (!mediaSession) {
33
+ throw this.unavailable('Media Session API not available in this browser.');
34
+ }
35
+ mediaSession.setActionHandler(options.action, handler);
36
+ }
37
+ async setPositionState(options) {
38
+ const mediaSession = navigator.mediaSession;
39
+ if (!mediaSession) {
40
+ throw this.unavailable('Media Session API not available in this browser.');
41
+ }
42
+ mediaSession.setPositionState(options);
43
+ }
44
+ }
45
+
46
+ var web = /*#__PURE__*/Object.freeze({
47
+ __proto__: null,
48
+ MediaSessionWeb: MediaSessionWeb
49
+ });
50
+
51
+ exports.MediaSession = MediaSession;
52
+
53
+ return exports;
54
+
55
+ })({}, capacitorExports);
56
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst MediaSession = registerPlugin('MediaSession', {\n web: () => import('./web').then((m) => new m.MediaSessionWeb()),\n ios: () => import('./web').then((m) => new m.MediaSessionWeb()),\n});\nexport * from './definitions';\nexport { MediaSession };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class MediaSessionWeb extends WebPlugin {\n async setMetadata(options) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n const MediaMetadataCtor = window.MediaMetadata;\n if (MediaMetadataCtor) {\n mediaSession.metadata = new MediaMetadataCtor(options);\n }\n else {\n mediaSession.metadata = options;\n }\n }\n async setPlaybackState(options) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.playbackState = options.playbackState;\n }\n async setActionHandler(options, handler) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.setActionHandler(options.action, handler);\n }\n async setPositionState(options) {\n const mediaSession = navigator.mediaSession;\n if (!mediaSession) {\n throw this.unavailable('Media Session API not available in this browser.');\n }\n mediaSession.setPositionState(options);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACnE,CAAC;;ICHM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;IAC/B,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;IACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;IAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;IACtF,QAAQ;IACR,QAAQ,MAAM,iBAAiB,GAAG,MAAM,CAAC,aAAa;IACtD,QAAQ,IAAI,iBAAiB,EAAE;IAC/B,YAAY,YAAY,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAClE,QAAQ;IACR,aAAa;IACb,YAAY,YAAY,CAAC,QAAQ,GAAG,OAAO;IAC3C,QAAQ;IACR,IAAI;IACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE;IACpC,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;IACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;IAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;IACtF,QAAQ;IACR,QAAQ,YAAY,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa;IAC1D,IAAI;IACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE;IAC7C,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;IACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;IAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;IACtF,QAAQ;IACR,QAAQ,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC;IAC9D,IAAI;IACJ,IAAI,MAAM,gBAAgB,CAAC,OAAO,EAAE;IACpC,QAAQ,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY;IACnD,QAAQ,IAAI,CAAC,YAAY,EAAE;IAC3B,YAAY,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC;IACtF,QAAQ;IACR,QAAQ,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC;IAC9C,IAAI;IACJ;;;;;;;;;;;;;;;"}
@@ -0,0 +1,9 @@
1
+ import Capacitor
2
+ import Foundation
3
+
4
+ @objc(MediaSessionPlugin)
5
+ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
6
+ public let identifier = "MediaSessionPlugin"
7
+ public let jsName = "MediaSession"
8
+ public let pluginMethods: [CAPPluginMethod] = []
9
+ }
@@ -0,0 +1,15 @@
1
+ import XCTest
2
+ @testable import MediaSessionPlugin
3
+
4
+ class MediaSessionTests: XCTestCase {
5
+ func testEcho() {
6
+ // This is an example of a functional test case for a plugin.
7
+ // Use XCTAssert and related functions to verify your tests produce the correct results.
8
+
9
+ let implementation = MediaSession()
10
+ let value = "Hello, World!"
11
+ let result = implementation.echo(value)
12
+
13
+ XCTAssertEqual(value, result)
14
+ }
15
+ }