@capgo/capacitor-media-session 7.2.9 → 7.3.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.
- package/{CapgoMediaSession.podspec → CapgoCapacitorMediaSession.podspec} +2 -1
- package/Package.swift +2 -2
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/capgo/mediasession/MediaSessionPlugin.java +1 -1
- package/dist/esm/definitions.d.ts +3 -3
- package/dist/esm/web.js.map +1 -1
- package/ios/Sources/MediaSessionPlugin/MediaSessionPlugin.swift +17 -10
- package/package.json +14 -10
|
@@ -3,7 +3,7 @@ require 'json'
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = '
|
|
6
|
+
s.name = 'CapgoCapacitorMediaSession'
|
|
7
7
|
s.version = package['version']
|
|
8
8
|
s.summary = package['description']
|
|
9
9
|
s.license = package['license']
|
|
@@ -15,3 +15,4 @@ Pod::Spec.new do |s|
|
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
16
|
s.swift_version = '5.1'
|
|
17
17
|
end
|
|
18
|
+
|
package/Package.swift
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import PackageDescription
|
|
3
3
|
|
|
4
4
|
let package = Package(
|
|
5
|
-
name: "
|
|
5
|
+
name: "CapgoCapacitorMediaSession",
|
|
6
6
|
platforms: [.iOS(.v14)],
|
|
7
7
|
products: [
|
|
8
8
|
.library(
|
|
9
|
-
name: "
|
|
9
|
+
name: "CapgoCapacitorMediaSession",
|
|
10
10
|
targets: ["MediaSessionPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
package/android/build.gradle
CHANGED
|
@@ -19,8 +19,8 @@ buildscript {
|
|
|
19
19
|
apply plugin: 'com.android.library'
|
|
20
20
|
|
|
21
21
|
android {
|
|
22
|
-
namespace "com.capgo.mediasession"
|
|
23
|
-
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
22
|
+
namespace = "com.capgo.mediasession"
|
|
23
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
|
|
24
24
|
defaultConfig {
|
|
25
25
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
|
|
26
26
|
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
|
|
@@ -35,7 +35,7 @@ android {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
lintOptions {
|
|
38
|
-
abortOnError false
|
|
38
|
+
abortOnError = false
|
|
39
39
|
}
|
|
40
40
|
compileOptions {
|
|
41
41
|
sourceCompatibility JavaVersion.VERSION_21
|
|
@@ -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.
|
|
33
|
+
private final String pluginVersion = "7.3.0";
|
|
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
|
|
7
|
-
export
|
|
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
|
|
20
|
+
export type ActionHandler = (details: ActionDetails) => void;
|
|
21
21
|
interface ActionDetails {
|
|
22
22
|
action: MediaSessionAction;
|
|
23
23
|
seekTime?: number | null;
|
package/dist/esm/web.js.map
CHANGED
|
@@ -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;
|
|
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.
|
|
7
|
+
private let pluginVersion: String = "7.3.0"
|
|
8
8
|
public let identifier = "MediaSessionPlugin"
|
|
9
9
|
public let jsName = "MediaSession"
|
|
10
10
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -18,9 +18,9 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
18
18
|
private var nowPlayingInfo: [String: Any] = [:]
|
|
19
19
|
private var registeredCommands: Set<String> = []
|
|
20
20
|
|
|
21
|
+
/// Sets the Now Playing metadata (title, artist, album, artwork).
|
|
21
22
|
@objc func setMetadata(_ call: CAPPluginCall) {
|
|
22
23
|
DispatchQueue.main.async {
|
|
23
|
-
let nowPlayingInfo = MPNowPlayingInfoCenter.default()
|
|
24
24
|
var info: [String: Any] = [:]
|
|
25
25
|
|
|
26
26
|
if let title = call.getString("title") {
|
|
@@ -42,17 +42,18 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
42
42
|
if let image = image {
|
|
43
43
|
info[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(boundsSize: image.size) { _ in image }
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
self.updateNowPlayingInfo(info)
|
|
46
46
|
call.resolve()
|
|
47
47
|
}
|
|
48
48
|
return
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
self.updateNowPlayingInfo(info)
|
|
52
52
|
call.resolve()
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/// Updates the playback state (playing/paused/none).
|
|
56
57
|
@objc func setPlaybackState(_ call: CAPPluginCall) {
|
|
57
58
|
guard let stateString = call.getString("playbackState") else {
|
|
58
59
|
call.reject("playbackState is required")
|
|
@@ -60,8 +61,7 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
DispatchQueue.main.async {
|
|
63
|
-
|
|
64
|
-
var info = nowPlayingInfo.nowPlayingInfo ?? [:]
|
|
64
|
+
var info = self.nowPlayingInfo
|
|
65
65
|
|
|
66
66
|
switch stateString {
|
|
67
67
|
case "playing":
|
|
@@ -72,11 +72,12 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
72
72
|
info[MPNowPlayingInfoPropertyPlaybackRate] = 0.0
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
self.updateNowPlayingInfo(info)
|
|
76
76
|
call.resolve()
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/// Registers a native handler for a media session action.
|
|
80
81
|
@objc func setActionHandler(_ call: CAPPluginCall) {
|
|
81
82
|
guard let action = call.getString("action") else {
|
|
82
83
|
call.reject("action is required")
|
|
@@ -138,10 +139,10 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
|
|
142
|
+
/// Updates playback position state (duration, position, playbackRate).
|
|
141
143
|
@objc func setPositionState(_ call: CAPPluginCall) {
|
|
142
144
|
DispatchQueue.main.async {
|
|
143
|
-
|
|
144
|
-
var info = nowPlayingInfo.nowPlayingInfo ?? [:]
|
|
145
|
+
var info = self.nowPlayingInfo
|
|
145
146
|
|
|
146
147
|
if let duration = call.getDouble("duration") {
|
|
147
148
|
info[MPMediaItemPropertyPlaybackDuration] = duration
|
|
@@ -153,11 +154,12 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
153
154
|
info[MPNowPlayingInfoPropertyPlaybackRate] = playbackRate
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
self.updateNowPlayingInfo(info)
|
|
157
158
|
call.resolve()
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
/// Returns the native plugin version.
|
|
161
163
|
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
162
164
|
call.resolve(["version": self.pluginVersion])
|
|
163
165
|
}
|
|
@@ -189,4 +191,9 @@ public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
189
191
|
}
|
|
190
192
|
}.resume()
|
|
191
193
|
}
|
|
194
|
+
|
|
195
|
+
private func updateNowPlayingInfo(_ info: [String: Any]) {
|
|
196
|
+
nowPlayingInfo.merge(info) { _, new in new }
|
|
197
|
+
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
|
|
198
|
+
}
|
|
192
199
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-media-session",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
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",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"ios/Sources",
|
|
14
14
|
"ios/Tests",
|
|
15
15
|
"Package.swift",
|
|
16
|
-
"
|
|
16
|
+
"CapgoCapacitorMediaSession.podspec"
|
|
17
17
|
],
|
|
18
18
|
"author": "Martin Donadieu <martin@capgo.app>",
|
|
19
19
|
"license": "MPL-2.0",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"bugs": {
|
|
25
25
|
"url": "https://github.com/Cap-go/capacitor-media-session/issues"
|
|
26
26
|
},
|
|
27
|
+
"homepage": "https://capgo.app/docs/plugins/media-session/",
|
|
27
28
|
"keywords": [
|
|
28
29
|
"capacitor",
|
|
29
30
|
"plugin",
|
|
@@ -34,13 +35,13 @@
|
|
|
34
35
|
],
|
|
35
36
|
"scripts": {
|
|
36
37
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
37
|
-
"verify:ios": "xcodebuild -scheme
|
|
38
|
+
"verify:ios": "xcodebuild -scheme CapgoCapacitorMediaSession -destination generic/platform=iOS",
|
|
38
39
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
39
40
|
"verify:web": "npm run build",
|
|
40
41
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
41
42
|
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
42
43
|
"eslint": "eslint . --ext ts",
|
|
43
|
-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
44
|
+
"prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
44
45
|
"swiftlint": "node-swiftlint",
|
|
45
46
|
"docgen": "docgen --api MediaSessionPlugin --output-readme README.md --output-json dist/docs.json",
|
|
46
47
|
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
@@ -56,13 +57,16 @@
|
|
|
56
57
|
"@ionic/eslint-config": "^0.4.0",
|
|
57
58
|
"@ionic/prettier-config": "^4.0.0",
|
|
58
59
|
"@ionic/swiftlint-config": "^2.0.0",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
60
|
+
"@types/node": "^24.10.1",
|
|
61
|
+
"eslint": "^8.57.1",
|
|
62
|
+
"eslint-plugin-import": "^2.31.0",
|
|
63
|
+
"prettier": "^3.6.2",
|
|
64
|
+
"prettier-plugin-java": "^2.7.7",
|
|
65
|
+
"rimraf": "^6.1.0",
|
|
66
|
+
"rollup": "^4.53.2",
|
|
64
67
|
"swiftlint": "^2.0.0",
|
|
65
|
-
"typescript": "
|
|
68
|
+
"typescript": "^5.9.3",
|
|
69
|
+
"prettier-pretty-check": "^0.2.0"
|
|
66
70
|
},
|
|
67
71
|
"peerDependencies": {
|
|
68
72
|
"@capacitor/core": ">=7.0.0"
|