react-native-media-notification 0.3.3 → 0.3.4
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/ios/MediaControls.mm +32 -2
- package/package.json +1 -1
package/ios/MediaControls.mm
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
@property (nonatomic, assign) BOOL hasListeners;
|
|
8
8
|
@property (nonatomic, assign) BOOL audioInterrupted;
|
|
9
9
|
@property (nonatomic, assign) BOOL explictlyPaused;
|
|
10
|
+
@property (nonatomic, assign) BOOL isSeeking;
|
|
11
|
+
@property (nonatomic, assign) BOOL isBackwardSeeking;
|
|
12
|
+
@property (nonatomic, assign) float seekTime;
|
|
13
|
+
@property (nonatomic, assign) NSTimer* seekTimer;
|
|
10
14
|
@end
|
|
11
15
|
|
|
12
16
|
@implementation MediaControls
|
|
@@ -256,12 +260,29 @@ RCT_EXPORT_METHOD(enableBackgroundMode:(BOOL) enabled){
|
|
|
256
260
|
}
|
|
257
261
|
|
|
258
262
|
- (MPRemoteCommandHandlerStatus)handleSeekForwardCommand:(MPRemoteCommandEvent *)event {
|
|
259
|
-
|
|
263
|
+
if (self.isSeeking) {
|
|
264
|
+
[self emitEvent:@"seek" position:[NSNumber numberWithFloat:self.seekTime]];
|
|
265
|
+
self.isSeeking = false;
|
|
266
|
+
[self.seekTimer invalidate];
|
|
267
|
+
self.seekTimer = nil;
|
|
268
|
+
return MPRemoteCommandHandlerStatusSuccess;
|
|
269
|
+
}
|
|
270
|
+
self.isSeeking = true;
|
|
271
|
+
self.isBackwardSeeking = false;
|
|
272
|
+
|
|
273
|
+
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
|
|
274
|
+
self.seekTime = [[center.nowPlayingInfo objectForKey:MPNowPlayingInfoPropertyElapsedPlaybackTime] floatValue];
|
|
275
|
+
self.seekTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(seekTimerCallback) userInfo:nil repeats:YES];
|
|
260
276
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
261
277
|
}
|
|
262
278
|
|
|
263
279
|
- (MPRemoteCommandHandlerStatus)handleSeekBackwardCommand:(MPRemoteCommandEvent *)event {
|
|
264
|
-
|
|
280
|
+
self.isSeeking = true;
|
|
281
|
+
self.isBackwardSeeking = true;
|
|
282
|
+
|
|
283
|
+
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
|
|
284
|
+
self.seekTime = [[center.nowPlayingInfo objectForKey:MPNowPlayingInfoPropertyElapsedPlaybackTime] floatValue];
|
|
285
|
+
self.seekTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(seekTimerCallback) userInfo:nil repeats:YES];
|
|
265
286
|
return MPRemoteCommandHandlerStatusSuccess;
|
|
266
287
|
}
|
|
267
288
|
|
|
@@ -326,6 +347,15 @@ RCT_EXPORT_METHOD(enableBackgroundMode:(BOOL) enabled){
|
|
|
326
347
|
});
|
|
327
348
|
}
|
|
328
349
|
|
|
350
|
+
-(void)seekTimerCallback{
|
|
351
|
+
self.seekTime += 2 * (self.isBackwardSeeking ? -1 : 1);
|
|
352
|
+
|
|
353
|
+
MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
|
|
354
|
+
NSMutableDictionary *mediaDict = [[NSMutableDictionary alloc] initWithDictionary: center.nowPlayingInfo];
|
|
355
|
+
mediaDict[MPNowPlayingInfoPropertyElapsedPlaybackTime] = @(self.seekTime);
|
|
356
|
+
center.nowPlayingInfo = mediaDict;
|
|
357
|
+
}
|
|
358
|
+
|
|
329
359
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
330
360
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
331
361
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-media-notification",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Display and manage media style notifications based on react-native-music-control",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|