@capgo/capacitor-media-session 8.0.4 → 8.0.6
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 = "8.0.
|
|
33
|
+
private final String pluginVersion = "8.0.6";
|
|
34
34
|
|
|
35
35
|
private static final String TAG = "CapgoMediaSession";
|
|
36
36
|
|
|
@@ -4,7 +4,7 @@ import MediaPlayer
|
|
|
4
4
|
|
|
5
5
|
@objc(MediaSessionPlugin)
|
|
6
6
|
public class MediaSessionPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
7
|
-
private let pluginVersion: String = "8.0.
|
|
7
|
+
private let pluginVersion: String = "8.0.6"
|
|
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
|
}
|