react-native-audio-api 0.11.0-nightly-db51488-20251207 → 0.11.0-nightly-6ba0571-20251209
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/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +164 -16
- package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioPlayer.kt +10 -8
- package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +10 -8
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +8 -23
- package/android/src/main/java/com/swmansion/audioapi/system/CentralizedForegroundService.kt +127 -0
- package/android/src/main/java/com/swmansion/audioapi/system/ForegroundServiceManager.kt +116 -0
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +115 -107
- package/android/src/main/java/com/swmansion/audioapi/system/PermissionRequestListener.kt +2 -1
- package/android/src/main/java/com/swmansion/audioapi/system/notification/BaseNotification.kt +47 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/NotificationRegistry.kt +191 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +668 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotificationReceiver.kt +33 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotification.kt +303 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +43 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/SimpleNotification.kt +119 -0
- package/ios/audioapi/ios/AudioAPIModule.h +2 -2
- package/ios/audioapi/ios/AudioAPIModule.mm +108 -18
- package/ios/audioapi/ios/system/AudioEngine.mm +2 -2
- package/ios/audioapi/ios/system/AudioSessionManager.mm +1 -1
- package/ios/audioapi/ios/system/NotificationManager.mm +1 -1
- package/ios/audioapi/ios/system/notification/BaseNotification.h +58 -0
- package/ios/audioapi/ios/system/notification/NotificationRegistry.h +70 -0
- package/ios/audioapi/ios/system/notification/NotificationRegistry.mm +172 -0
- package/ios/audioapi/ios/system/notification/PlaybackNotification.h +27 -0
- package/ios/audioapi/ios/system/notification/PlaybackNotification.mm +427 -0
- package/lib/commonjs/api.js +59 -10
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/api.web.js +27 -14
- package/lib/commonjs/api.web.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +6 -9
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/commonjs/system/index.js +13 -0
- package/lib/commonjs/system/index.js.map +1 -1
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js +135 -0
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/commonjs/system/notification/RecordingNotificationManager.js +182 -0
- package/lib/commonjs/system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/commonjs/system/notification/SimpleNotificationManager.js +122 -0
- package/lib/commonjs/system/notification/SimpleNotificationManager.js.map +1 -0
- package/lib/commonjs/system/notification/index.js +45 -0
- package/lib/commonjs/system/notification/index.js.map +1 -0
- package/lib/commonjs/system/notification/types.js +6 -0
- package/lib/commonjs/system/notification/types.js.map +1 -0
- package/lib/commonjs/web-system/index.js +17 -0
- package/lib/commonjs/web-system/index.js.map +1 -0
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js +34 -0
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js +34 -0
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/commonjs/web-system/notification/index.js +21 -0
- package/lib/commonjs/web-system/notification/index.js.map +1 -0
- package/lib/module/api.js +5 -1
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +3 -1
- package/lib/module/api.web.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/system/AudioManager.js +6 -9
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/module/system/index.js +1 -0
- package/lib/module/system/index.js.map +1 -1
- package/lib/module/system/notification/PlaybackNotificationManager.js +131 -0
- package/lib/module/system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/module/system/notification/RecordingNotificationManager.js +178 -0
- package/lib/module/system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/module/system/notification/SimpleNotificationManager.js +118 -0
- package/lib/module/system/notification/SimpleNotificationManager.js.map +1 -0
- package/lib/module/system/notification/index.js +7 -0
- package/lib/module/system/notification/index.js.map +1 -0
- package/lib/module/system/notification/types.js +4 -0
- package/lib/module/system/notification/types.js.map +1 -0
- package/lib/module/web-system/index.js +4 -0
- package/lib/module/web-system/index.js.map +1 -0
- package/lib/module/web-system/notification/PlaybackNotificationManager.js +30 -0
- package/lib/module/web-system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/module/web-system/notification/RecordingNotificationManager.js +30 -0
- package/lib/module/web-system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/module/web-system/notification/index.js +5 -0
- package/lib/module/web-system/notification/index.js.map +1 -0
- package/lib/typescript/api.d.ts +3 -1
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +3 -1
- package/lib/typescript/api.web.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +4 -18
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +16 -5
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +4 -5
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/system/index.d.ts +1 -0
- package/lib/typescript/system/index.d.ts.map +1 -1
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts +22 -0
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts.map +1 -0
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts +23 -0
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts.map +1 -0
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts +20 -0
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts.map +1 -0
- package/lib/typescript/system/notification/index.d.ts +5 -0
- package/lib/typescript/system/notification/index.d.ts.map +1 -0
- package/lib/typescript/system/notification/types.d.ts +65 -0
- package/lib/typescript/system/notification/types.d.ts.map +1 -0
- package/lib/typescript/system/types.d.ts +0 -16
- package/lib/typescript/system/types.d.ts.map +1 -1
- package/lib/typescript/web-system/index.d.ts +2 -0
- package/lib/typescript/web-system/index.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts +19 -0
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts +19 -0
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/index.d.ts +3 -0
- package/lib/typescript/web-system/notification/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/api.ts +17 -2
- package/src/api.web.ts +7 -2
- package/src/events/types.ts +4 -20
- package/src/specs/NativeAudioAPIModule.ts +23 -7
- package/src/system/AudioManager.ts +10 -23
- package/src/system/index.ts +1 -0
- package/src/system/notification/PlaybackNotificationManager.ts +193 -0
- package/src/system/notification/RecordingNotificationManager.ts +242 -0
- package/src/system/notification/SimpleNotificationManager.ts +170 -0
- package/src/system/notification/index.ts +4 -0
- package/src/system/notification/types.ts +110 -0
- package/src/system/types.ts +0 -18
- package/src/web-system/index.ts +1 -0
- package/src/web-system/notification/PlaybackNotificationManager.ts +60 -0
- package/src/web-system/notification/RecordingNotificationManager.ts +60 -0
- package/src/web-system/notification/index.ts +2 -0
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +0 -347
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +0 -273
- package/android/src/main/java/com/swmansion/audioapi/system/MediaReceiver.kt +0 -57
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionCallback.kt +0 -61
- package/ios/audioapi/ios/system/LockScreenManager.h +0 -23
- package/ios/audioapi/ios/system/LockScreenManager.mm +0 -314
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
package com.swmansion.audioapi.system
|
|
2
|
-
|
|
3
|
-
import android.os.Bundle
|
|
4
|
-
import android.support.v4.media.session.MediaSessionCompat
|
|
5
|
-
import android.util.Log
|
|
6
|
-
import com.swmansion.audioapi.AudioAPIModule
|
|
7
|
-
import java.lang.ref.WeakReference
|
|
8
|
-
|
|
9
|
-
class MediaSessionCallback(
|
|
10
|
-
private val audioAPIModule: WeakReference<AudioAPIModule>,
|
|
11
|
-
private val mediaNotificationManager: WeakReference<MediaNotificationManager>,
|
|
12
|
-
) : MediaSessionCompat.Callback() {
|
|
13
|
-
override fun onPlay() {
|
|
14
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remotePlay", mapOf())
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
override fun onPause() {
|
|
18
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remotePause", mapOf())
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
override fun onStop() {
|
|
22
|
-
mediaNotificationManager.get()?.cancelNotification()
|
|
23
|
-
MediaSessionManager.stopForegroundServiceIfNecessary()
|
|
24
|
-
|
|
25
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remoteStop", mapOf())
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
override fun onSkipToNext() {
|
|
29
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remoteNextTrack", mapOf())
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
override fun onSkipToPrevious() {
|
|
33
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remotePreviousTrack", mapOf())
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
override fun onFastForward() {
|
|
37
|
-
val body = HashMap<String, Any>().apply { put("value", 15) }
|
|
38
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remoteSkipForward", body)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
override fun onRewind() {
|
|
42
|
-
val body = HashMap<String, Any>().apply { put("value", 15) }
|
|
43
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remoteSkipBackward", body)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
override fun onSeekTo(pos: Long) {
|
|
47
|
-
val body = HashMap<String, Any>().apply { put("value", (pos.toDouble() / 1000)) }
|
|
48
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("remoteChangePlaybackPosition", body)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
override fun onCustomAction(
|
|
52
|
-
action: String?,
|
|
53
|
-
extras: Bundle?,
|
|
54
|
-
) {
|
|
55
|
-
when (action) {
|
|
56
|
-
"SkipForward" -> onFastForward()
|
|
57
|
-
"SkipBackward" -> onRewind()
|
|
58
|
-
else -> Log.w("MediaSessionCallback", "Unknown custom action: $action")
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#import <AVFoundation/AVFoundation.h>
|
|
4
|
-
#import <Foundation/Foundation.h>
|
|
5
|
-
#import <MediaPlayer/MediaPlayer.h>
|
|
6
|
-
|
|
7
|
-
@class AudioAPIModule;
|
|
8
|
-
|
|
9
|
-
@interface LockScreenManager : NSObject
|
|
10
|
-
|
|
11
|
-
@property (nonatomic, weak) AudioAPIModule *audioAPIModule;
|
|
12
|
-
|
|
13
|
-
@property (nonatomic, weak) MPNowPlayingInfoCenter *playingInfoCenter;
|
|
14
|
-
@property (nonatomic, copy) NSString *artworkUrl;
|
|
15
|
-
|
|
16
|
-
- (instancetype)initWithAudioAPIModule:(AudioAPIModule *)audioAPIModule;
|
|
17
|
-
- (void)cleanup;
|
|
18
|
-
|
|
19
|
-
- (void)setLockScreenInfo:(NSDictionary *)info;
|
|
20
|
-
- (void)resetLockScreenInfo;
|
|
21
|
-
- (void)enableRemoteCommand:(NSString *)name enabled:(BOOL)enabled;
|
|
22
|
-
|
|
23
|
-
@end
|
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
#import <MediaPlayer/MediaPlayer.h>
|
|
2
|
-
#import <audioapi/ios/AudioAPIModule.h>
|
|
3
|
-
#import <audioapi/ios/system/LockScreenManager.h>
|
|
4
|
-
|
|
5
|
-
#define LOCK_SCREEN_INFO \
|
|
6
|
-
@{ \
|
|
7
|
-
@"album" : MPMediaItemPropertyAlbumTitle, \
|
|
8
|
-
@"artist" : MPMediaItemPropertyArtist, \
|
|
9
|
-
@"duration" : MPMediaItemPropertyPlaybackDuration, \
|
|
10
|
-
@"title" : MPMediaItemPropertyTitle, \
|
|
11
|
-
@"speed" : MPNowPlayingInfoPropertyPlaybackRate, \
|
|
12
|
-
@"elapsedTime" : MPNowPlayingInfoPropertyElapsedPlaybackTime, \
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@implementation LockScreenManager
|
|
16
|
-
|
|
17
|
-
- (instancetype)initWithAudioAPIModule:(AudioAPIModule *)audioAPIModule
|
|
18
|
-
{
|
|
19
|
-
if (self = [super init]) {
|
|
20
|
-
self.audioAPIModule = audioAPIModule;
|
|
21
|
-
self.playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];
|
|
22
|
-
|
|
23
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
24
|
-
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return self;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
- (void)cleanup
|
|
32
|
-
{
|
|
33
|
-
NSLog(@"[LockScreenManager] cleanup");
|
|
34
|
-
[self resetLockScreenInfo];
|
|
35
|
-
|
|
36
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
37
|
-
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
- (void)setLockScreenInfo:(NSDictionary *)info
|
|
42
|
-
{
|
|
43
|
-
self.playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];
|
|
44
|
-
|
|
45
|
-
// now playing info(lock screen info)
|
|
46
|
-
NSMutableDictionary *lockScreenInfoDict;
|
|
47
|
-
|
|
48
|
-
if (self.playingInfoCenter.nowPlayingInfo == nil) {
|
|
49
|
-
lockScreenInfoDict = [NSMutableDictionary dictionary];
|
|
50
|
-
} else {
|
|
51
|
-
lockScreenInfoDict =
|
|
52
|
-
[[NSMutableDictionary alloc] initWithDictionary:self.playingInfoCenter.nowPlayingInfo];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
for (NSString *key in LOCK_SCREEN_INFO) {
|
|
56
|
-
if ([info objectForKey:key] != nil) {
|
|
57
|
-
[lockScreenInfoDict setValue:[info objectForKey:key]
|
|
58
|
-
forKey:[LOCK_SCREEN_INFO objectForKey:key]];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
self.playingInfoCenter.nowPlayingInfo = lockScreenInfoDict;
|
|
63
|
-
|
|
64
|
-
// playback state
|
|
65
|
-
NSString *state = [info objectForKey:@"state"];
|
|
66
|
-
|
|
67
|
-
if (state != nil) {
|
|
68
|
-
if ([state isEqualToString:@"state_playing"]) {
|
|
69
|
-
self.playingInfoCenter.playbackState = MPNowPlayingPlaybackStatePlaying;
|
|
70
|
-
} else if ([state isEqualToString:@"state_paused"]) {
|
|
71
|
-
self.playingInfoCenter.playbackState = MPNowPlayingPlaybackStatePaused;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
self.playingInfoCenter.playbackState = MPNowPlayingPlaybackStatePaused;
|
|
76
|
-
|
|
77
|
-
// artwork
|
|
78
|
-
NSString *artworkUrl = [self getArtworkUrl:[info objectForKey:@"artwork"]];
|
|
79
|
-
[self updateArtworkIfNeeded:artworkUrl];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
- (void)resetLockScreenInfo
|
|
83
|
-
{
|
|
84
|
-
self.playingInfoCenter = [MPNowPlayingInfoCenter defaultCenter];
|
|
85
|
-
self.playingInfoCenter.nowPlayingInfo = nil;
|
|
86
|
-
self.artworkUrl = nil;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
- (NSString *)getArtworkUrl:(NSString *)artwork
|
|
90
|
-
{
|
|
91
|
-
NSString *artworkUrl = nil;
|
|
92
|
-
|
|
93
|
-
if (artwork) {
|
|
94
|
-
if ([artwork isKindOfClass:[NSString class]]) {
|
|
95
|
-
artworkUrl = artwork;
|
|
96
|
-
} else if ([[artwork valueForKey:@"uri"] isKindOfClass:[NSString class]]) {
|
|
97
|
-
artworkUrl = [artwork valueForKey:@"uri"];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return artworkUrl;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
- (void)updateArtworkIfNeeded:(id)artworkUrl
|
|
105
|
-
{
|
|
106
|
-
if (artworkUrl == nil) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
|
|
111
|
-
if ([artworkUrl isEqualToString:self.artworkUrl] &&
|
|
112
|
-
[center.nowPlayingInfo objectForKey:MPMediaItemPropertyArtwork] != nil) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
self.artworkUrl = artworkUrl;
|
|
117
|
-
|
|
118
|
-
// Custom handling of artwork in another thread, will be loaded async
|
|
119
|
-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
|
|
120
|
-
UIImage *image = nil;
|
|
121
|
-
|
|
122
|
-
// check whether artwork path is present
|
|
123
|
-
if ([artworkUrl isEqual:@""]) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// artwork is url download from the interwebs
|
|
128
|
-
if ([artworkUrl hasPrefix:@"http://"] || [artworkUrl hasPrefix:@"https://"]) {
|
|
129
|
-
NSURL *imageURL = [NSURL URLWithString:artworkUrl];
|
|
130
|
-
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
|
|
131
|
-
image = [UIImage imageWithData:imageData];
|
|
132
|
-
} else {
|
|
133
|
-
NSString *localArtworkUrl = [artworkUrl stringByReplacingOccurrencesOfString:@"file://"
|
|
134
|
-
withString:@""];
|
|
135
|
-
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:localArtworkUrl];
|
|
136
|
-
if (fileExists) {
|
|
137
|
-
image = [UIImage imageNamed:localArtworkUrl];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Check if image was available otherwise don't do anything
|
|
142
|
-
if (image == nil) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// check whether image is loaded
|
|
147
|
-
CGImageRef cgref = [image CGImage];
|
|
148
|
-
CIImage *cim = [image CIImage];
|
|
149
|
-
|
|
150
|
-
if (cim == nil && cgref == NULL) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
155
|
-
// Check if URL wasn't changed in the meantime
|
|
156
|
-
if (![artworkUrl isEqual:self.artworkUrl]) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
|
|
161
|
-
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc]
|
|
162
|
-
initWithBoundsSize:image.size
|
|
163
|
-
requestHandler:^UIImage *_Nonnull(CGSize size) { return image; }];
|
|
164
|
-
NSMutableDictionary *mediaDict = (center.nowPlayingInfo != nil)
|
|
165
|
-
? [[NSMutableDictionary alloc] initWithDictionary:center.nowPlayingInfo]
|
|
166
|
-
: [NSMutableDictionary dictionary];
|
|
167
|
-
[mediaDict setValue:artwork forKey:MPMediaItemPropertyArtwork];
|
|
168
|
-
center.nowPlayingInfo = mediaDict;
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
- (void)enableRemoteCommand:(NSString *)name enabled:(BOOL)enabled
|
|
174
|
-
{
|
|
175
|
-
MPRemoteCommandCenter *remoteCenter = [MPRemoteCommandCenter sharedCommandCenter];
|
|
176
|
-
|
|
177
|
-
if ([name isEqual:@"remotePlay"]) {
|
|
178
|
-
[self enableCommand:remoteCenter.playCommand withSelector:@selector(onPlay:) enabled:enabled];
|
|
179
|
-
} else if ([name isEqual:@"remotePause"]) {
|
|
180
|
-
[self enableCommand:remoteCenter.pauseCommand withSelector:@selector(onPause:) enabled:enabled];
|
|
181
|
-
} else if ([name isEqual:@"remoteStop"]) {
|
|
182
|
-
[self enableCommand:remoteCenter.stopCommand withSelector:@selector(onStop:) enabled:enabled];
|
|
183
|
-
} else if ([name isEqual:@"remoteTogglePlayPause"]) {
|
|
184
|
-
[self enableCommand:remoteCenter.togglePlayPauseCommand
|
|
185
|
-
withSelector:@selector(onTogglePlayPause:)
|
|
186
|
-
enabled:enabled];
|
|
187
|
-
} else if ([name isEqual:@"remoteChangePlaybackRate"]) {
|
|
188
|
-
[self enableCommand:remoteCenter.changePlaybackRateCommand
|
|
189
|
-
withSelector:@selector(onChangePlaybackRate:)
|
|
190
|
-
enabled:enabled];
|
|
191
|
-
} else if ([name isEqual:@"remoteNextTrack"]) {
|
|
192
|
-
[self enableCommand:remoteCenter.nextTrackCommand
|
|
193
|
-
withSelector:@selector(onNextTrack:)
|
|
194
|
-
enabled:enabled];
|
|
195
|
-
} else if ([name isEqual:@"remotePreviousTrack"]) {
|
|
196
|
-
[self enableCommand:remoteCenter.previousTrackCommand
|
|
197
|
-
withSelector:@selector(onPreviousTrack:)
|
|
198
|
-
enabled:enabled];
|
|
199
|
-
} else if ([name isEqual:@"remoteSkipForward"]) {
|
|
200
|
-
remoteCenter.skipForwardCommand.preferredIntervals = @[ @15 ];
|
|
201
|
-
[self enableCommand:remoteCenter.skipForwardCommand
|
|
202
|
-
withSelector:@selector(onSkipForward:)
|
|
203
|
-
enabled:enabled];
|
|
204
|
-
} else if ([name isEqual:@"remoteSkipBackward"]) {
|
|
205
|
-
remoteCenter.skipBackwardCommand.preferredIntervals = @[ @15 ];
|
|
206
|
-
[self enableCommand:remoteCenter.skipBackwardCommand
|
|
207
|
-
withSelector:@selector(onSkipBackward:)
|
|
208
|
-
enabled:enabled];
|
|
209
|
-
} else if ([name isEqual:@"remoteSeekForward"]) {
|
|
210
|
-
[self enableCommand:remoteCenter.seekForwardCommand
|
|
211
|
-
withSelector:@selector(onSeekForward:)
|
|
212
|
-
enabled:enabled];
|
|
213
|
-
} else if ([name isEqual:@"remoteSeekBackward"]) {
|
|
214
|
-
[self enableCommand:remoteCenter.seekBackwardCommand
|
|
215
|
-
withSelector:@selector(onSeekBackward:)
|
|
216
|
-
enabled:enabled];
|
|
217
|
-
} else if ([name isEqual:@"remoteChangePlaybackPosition"]) {
|
|
218
|
-
[self enableCommand:remoteCenter.changePlaybackPositionCommand
|
|
219
|
-
withSelector:@selector(onChangePlaybackPosition:)
|
|
220
|
-
enabled:enabled];
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
- (void)enableCommand:(MPRemoteCommand *)command withSelector:(SEL)selector enabled:(BOOL)enabled
|
|
225
|
-
{
|
|
226
|
-
[command removeTarget:self action:selector];
|
|
227
|
-
if (enabled) {
|
|
228
|
-
[command addTarget:self action:selector];
|
|
229
|
-
}
|
|
230
|
-
command.enabled = enabled;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
- (MPRemoteCommandHandlerStatus)onPlay:(MPRemoteCommandEvent *)event
|
|
234
|
-
{
|
|
235
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remotePlay" eventBody:nil];
|
|
236
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
- (MPRemoteCommandHandlerStatus)onPause:(MPRemoteCommandEvent *)event
|
|
240
|
-
{
|
|
241
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remotePause" eventBody:nil];
|
|
242
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
- (MPRemoteCommandHandlerStatus)onStop:(MPRemoteCommandEvent *)event
|
|
246
|
-
{
|
|
247
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteStop" eventBody:nil];
|
|
248
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
- (MPRemoteCommandHandlerStatus)onTogglePlayPause:(MPRemoteCommandEvent *)event
|
|
252
|
-
{
|
|
253
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteTogglePlayPause" eventBody:nil];
|
|
254
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
- (MPRemoteCommandHandlerStatus)onChangePlaybackRate:(MPChangePlaybackRateCommandEvent *)event
|
|
258
|
-
{
|
|
259
|
-
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.playbackRate]};
|
|
260
|
-
|
|
261
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteChangePlaybackRate" eventBody:body];
|
|
262
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
- (MPRemoteCommandHandlerStatus)onNextTrack:(MPRemoteCommandEvent *)event
|
|
266
|
-
{
|
|
267
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteNextTrack" eventBody:nil];
|
|
268
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
- (MPRemoteCommandHandlerStatus)onPreviousTrack:(MPRemoteCommandEvent *)event
|
|
272
|
-
{
|
|
273
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remotePreviousTrack" eventBody:nil];
|
|
274
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
- (MPRemoteCommandHandlerStatus)onSeekForward:(MPRemoteCommandEvent *)event
|
|
278
|
-
{
|
|
279
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSeekForward" eventBody:nil];
|
|
280
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
- (MPRemoteCommandHandlerStatus)onSeekBackward:(MPRemoteCommandEvent *)event
|
|
284
|
-
{
|
|
285
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSeekBackward" eventBody:nil];
|
|
286
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
- (MPRemoteCommandHandlerStatus)onSkipForward:(MPSkipIntervalCommandEvent *)event
|
|
290
|
-
{
|
|
291
|
-
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.interval]};
|
|
292
|
-
|
|
293
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSkipForward" eventBody:body];
|
|
294
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
- (MPRemoteCommandHandlerStatus)onSkipBackward:(MPSkipIntervalCommandEvent *)event
|
|
298
|
-
{
|
|
299
|
-
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.interval]};
|
|
300
|
-
|
|
301
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteSkipBackward" eventBody:body];
|
|
302
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
- (MPRemoteCommandHandlerStatus)onChangePlaybackPosition:
|
|
306
|
-
(MPChangePlaybackPositionCommandEvent *)event
|
|
307
|
-
{
|
|
308
|
-
NSDictionary *body = @{@"value" : [NSNumber numberWithDouble:event.positionTime]};
|
|
309
|
-
|
|
310
|
-
[self.audioAPIModule invokeHandlerWithEventName:@"remoteChangePlaybackPosition" eventBody:body];
|
|
311
|
-
return MPRemoteCommandHandlerStatusSuccess;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
@end
|