@capgo/capacitor-media-session 7.2.8 → 7.2.10

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.
@@ -30,7 +30,7 @@ import org.json.JSONObject;
30
30
  @CapacitorPlugin(name = "MediaSession")
31
31
  public class MediaSessionPlugin extends Plugin {
32
32
 
33
- private final String pluginVersion = "7.2.8";
33
+ private final String pluginVersion = "7.2.10";
34
34
 
35
35
  private static final String TAG = "CapgoMediaSession";
36
36
 
@@ -3,8 +3,8 @@ export interface MediaImage {
3
3
  sizes?: string;
4
4
  type?: string;
5
5
  }
6
- export declare type MediaSessionPlaybackState = 'none' | 'paused' | 'playing';
7
- export declare type MediaSessionAction = 'play' | 'pause' | 'seekbackward' | 'seekforward' | 'previoustrack' | 'nexttrack' | 'seekto' | 'stop';
6
+ export type MediaSessionPlaybackState = 'none' | 'paused' | 'playing';
7
+ export type MediaSessionAction = 'play' | 'pause' | 'seekbackward' | 'seekforward' | 'previoustrack' | 'nexttrack' | 'seekto' | 'stop';
8
8
  export interface MetadataOptions {
9
9
  album?: string;
10
10
  artist?: string;
@@ -17,7 +17,7 @@ export interface PlaybackStateOptions {
17
17
  export interface ActionHandlerOptions {
18
18
  action: MediaSessionAction;
19
19
  }
20
- export declare type ActionHandler = (details: ActionDetails) => void;
20
+ export type ActionHandler = (details: ActionDetails) => void;
21
21
  interface ActionDetails {
22
22
  action: MediaSessionAction;
23
23
  seekTime?: number | null;
@@ -1 +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;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,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 async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n}\n"]}
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,CAAC;YAClB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;QAC7E,CAAC;QAED,MAAM,iBAAiB,GAAI,MAAc,CAAC,aAAa,CAAC;QACxD,IAAI,iBAAiB,EAAE,CAAC;YACtB,YAAY,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,OAAO,CAAC,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,YAAY,CAAC,QAAQ,GAAG,OAAO,CAAC;QAClC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAA6B;QAClD,MAAM,YAAY,GAAI,SAAiB,CAAC,YAAY,CAAC;QACrD,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;QAC7E,CAAC;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,CAAC;YAClB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;QAC7E,CAAC;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,CAAC;YAClB,MAAM,IAAI,CAAC,WAAW,CAAC,kDAAkD,CAAC,CAAC;QAC7E,CAAC;QACD,YAAY,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,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 async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n}\n"]}
@@ -4,7 +4,7 @@ import MediaPlayer
4
4
 
5
5
  @objc(MediaSessionPlugin)
6
6
  public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
7
- private let pluginVersion: String = "7.2.8"
7
+ private let pluginVersion: String = "7.2.10"
8
8
  public let identifier = "MediaSessionPlugin"
9
9
  public let jsName = "MediaSession"
10
10
  public let pluginMethods: [CAPPluginMethod] = [
@@ -20,7 +20,6 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
20
20
 
21
21
  @objc func setMetadata(_ call: CAPPluginCall) {
22
22
  DispatchQueue.main.async {
23
- let nowPlayingInfo = MPNowPlayingInfoCenter.default()
24
23
  var info: [String: Any] = [:]
25
24
 
26
25
  if let title = call.getString("title") {
@@ -42,13 +41,13 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
42
41
  if let image = image {
43
42
  info[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { _ in image }
44
43
  }
45
- nowPlayingInfo.nowPlayingInfo = info
44
+ self.updateNowPlayingInfo(info)
46
45
  call.resolve()
47
46
  }
48
47
  return
49
48
  }
50
49
 
51
- nowPlayingInfo.nowPlayingInfo = info
50
+ self.updateNowPlayingInfo(info)
52
51
  call.resolve()
53
52
  }
54
53
  }
@@ -60,8 +59,7 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
60
59
  }
61
60
 
62
61
  DispatchQueue.main.async {
63
- let nowPlayingInfo = MPNowPlayingInfoCenter.default()
64
- var info = nowPlayingInfo.nowPlayingInfo ?? [:]
62
+ var info = self.nowPlayingInfo
65
63
 
66
64
  switch stateString {
67
65
  case "playing":
@@ -72,7 +70,7 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
72
70
  info[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
73
71
  }
74
72
 
75
- nowPlayingInfo.nowPlayingInfo = info
73
+ self.updateNowPlayingInfo(info)
76
74
  call.resolve()
77
75
  }
78
76
  }
@@ -140,8 +138,7 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
140
138
 
141
139
  @objc func setPositionState(_ call: CAPPluginCall) {
142
140
  DispatchQueue.main.async {
143
- let nowPlayingInfo = MPNowPlayingInfoCenter.default()
144
- var info = nowPlayingInfo.nowPlayingInfo ?? [:]
141
+ var info = self.nowPlayingInfo
145
142
 
146
143
  if let duration = call.getDouble("duration") {
147
144
  info[MPMediaItemPropertyPlaybackDuration] = duration
@@ -153,7 +150,7 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
153
150
  info[MPNowPlayingInfoPropertyPlaybackRate] = playbackRate
154
151
  }
155
152
 
156
- nowPlayingInfo.nowPlayingInfo = info
153
+ self.updateNowPlayingInfo(info)
157
154
  call.resolve()
158
155
  }
159
156
  }
@@ -189,4 +186,9 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
189
186
  }
190
187
  }.resume()
191
188
  }
189
+
190
+ private func updateNowPlayingInfo(_ info: [String: Any]) {
191
+ nowPlayingInfo.merge(info) { _, new in new }
192
+ MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
193
+ }
192
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-media-session",
3
- "version": "7.2.8",
3
+ "version": "7.2.10",
4
4
  "description": "Capacitor plugin to expose media session controls of the device",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",